christien christien - 4 months ago 23
Swift Question

Swift Passing array of dictionary to NSMutableArray

I am trying to pass swift array of dictionaries to the NSMutableArray. But I am getting error "Cannot convert value of type [[String : Anyobject?]] to expected argument type NSMutableArray". Below is the code:

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(, forKey: "id")

Now passing this "ary" to the Objective C method as a NSMutableArray!



Replica of your issue:

    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")

    mutableArray =  NSMutableArray(array: ary)

Removing the optional did the trick!