参数types“AnyObject”不符合期望的typesNSCopying

我想在Swift使用NSDictionary ,我正面临着上述问题。 我有一个以下格式的字典:

 let xyz: NSMutableDictionary = ["1":[1,2,3,4,"1","n","1","2"],"2":[1,2,3,4,"+","o","6","2"]] 

我想迭代字典中的键并提取数组的第六个元素。 我尝试了以下; 但没有遇到任何运气:

 for keys in dictKeyMutableDict { let xCentVal = xyz[keys as! [NSCopying]][6] } 

我不断收到一个下标错误,如果我删除as! [NSCopying] as! [NSCopying] ,我收到上面的错误。 有谁知道如何处理这种情况?

删除NSMutableDictionary并使其变为可变的,使其成为一个变种。 现在你可以删除的as! [NSCopying] as! [NSCopying]

 var xyz = ["1":[1,2,3,4,"1","n","1","2"],"2":[1,2,3,4,"+","o","6","2"]] for keys in dictKeyMutableDict { let xCentVal = xyz[keys]![6] } 

或者更好的可选解开它:

 for keys in dictKeyMutableDict { if let v = xyz[keys] { let xCentVal = v[6] } }