我试图将字典的快速数组传递给NSMutableArray。但是我收到错误消息“无法将类型[[String:Anyobject?]]的值转换为预期的参数类型NSMutableArray”。下面是代码:
var ary : [[String:AnyObject?]] = []
var mutableDictionary = [String: AnyObject?]()
for c in buffer {
mutableDictionary.updateValue(c.Name, forKey: "name")
mutableDictionary.updateValue(c.Number, forKey: "phoneNumber")
mutableDictionary.updateValue(c.id, forKey: "id")
ary.append(mutableDictionary)
}
现在将此“ary”作为NSMutableArray传递给Objective C方法!
Manager.sharedInstance().List(ary)
最佳答案
您问题的副本:
var ary : [[String:AnyObject]] = []
var mutableDictionary = [String: AnyObject]()
var mutableArray:NSMutableArray!
for _ in 0...4 {
mutableDictionary.updateValue("adsf", forKey: "name")
mutableDictionary.updateValue("dsf", forKey: "phoneNumber")
mutableDictionary.updateValue("sdfd", forKey: "id")
ary.append(mutableDictionary)
}
mutableArray = NSMutableArray(array: ary)
删除可选的技巧!