[英]Could not cast value of type 'Swift._NativeDictionaryStorageOwner<Swift.String, Swift.AnyObject>' (0x40c2134) to 'NSArray' (0x383bb8d8)
Upon revisiting some code that seemed to work with Xcode7.3, I noticed that I am getting a Could not cast value of type 'Swift._NativeDictionaryStorageOwner' (0x40c2134) to 'NSArray' (0x383bb8d8). 在重新访问一些似乎可与Xcode7.3一起使用的代码后,我注意到我无法将类型'Swift._NativeDictionaryStorageOwner'(0x40c2134)的值强制转换为'NSArray'(0x383bb8d8)。
userdata.data = userOtherInfo[indexPath.row] as! userdata.data = userOtherInfo [indexPath.row]为! NSArray
NSArray
Here is the section of code that appears to be the problem: 这是似乎是问题所在的代码部分:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let userdata:SubContentsViewController! = SubContentsViewController()
let storyboard = UIStoryboard(name: "SubContentsViewController", bundle: nil)
let subContentsVC = storyboard.instantiateViewControllerWithIdentifier("SubContentsViewController") as! SubContentsViewController
userdata.data = userOtherInfo[indexPath.row] as! NSArray
self.navigationController?.pushViewController(subContentsVC, animated: true)
}
As you wrote in your comment 正如您在评论中所写
rows = value["search_result"] as? [[String: AnyObject]]
self.userOtherInfo = rows
rows / userOtherInfo
is an array of dictionaries ( [[String: AnyObject]]
) on success. rows / userOtherInfo
是成功的字典数组[[String: AnyObject]]
)。
That's what the error message says : 那就是错误消息说的:
Cannot cast Dictionary to Array.
无法将字典转换为数组。
The solution is very very simple. 解决方案非常非常简单。
Since the compiler already knows that userOtherInfo
contains an array of [String: AnyObject]
you need no casting at all. 由于编译器已经知道
userOtherInfo
包含[String: AnyObject]
的数组,因此根本不需要强制转换。
userdata.data = userOtherInfo[indexPath.row] // object is [String:AnyObject]
Make sure that userdata.data
is declared as [String:AnyObject]
or a more specific dictionary. 确保将
userdata.data
声明为[String:AnyObject]
或更具体的字典。
This solution is working fine for me. 这个解决方案对我来说很好。 let mutableDict = NSMutableDictionary(dictionary: newDictionaryResult!)
让mutableDict = NSMutableDictionary(dictionary:newDictionaryResult!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.