我正在尝试将快速的字典数组传递给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)
答案 0 :(得分:3)
您的问题的副本:
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)
删除可选项就行了!
答案 1 :(得分:1)
//试试这个
Manager.sharedInstance().List(NSMutableArray(array: ary as! NSArray))