我想將swift數組字典傳遞給NSMutableArray。但是我收到錯誤「無法將類型[[String:Anyobject?]]的值轉換爲期望的參數類型NSMutableArray」。以下是代碼:Swift將字典數組傳遞給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)
嘗試'Manager.sharedInstance()。List(ary as!NSMutableArray)'。 – Avi
不,它會崩潰,因爲從[[string:anyobject?]]投射到nsmutablearray總是失敗 – Hitesh
'NSMutableDictionary'不能包含optionals,也不能包含'NSMutableArray'。你必須在'AnyObject'上放下可選項。 – Avi