allenlinli allenlinli - 3 years ago 184
Swift Question

Could not cast value of type 'Swift._EmptyArrayStorage' to 'NSMutableArray' in iOS 11, Xcode 9

It looks like we can not covert empty

var
array in Swift into NSMutableArray in Objc.

var adultTravelerModels: [TravelerDataModel] = []
BookDataManger.sharedInstance().arraySelectedAdultPassenager = adultTravelerModels as! NSMutableArray
/* (lldb) po adultTravelerModels
0 elements */


The system version is iOS 11.0, Xcode 9.0.

How can we solve this?

Answer Source

Do like this:

BookDataManger.sharedInstance().arraySelectedAdultPassenager = NSMutableArray(array: adultTravelerModels)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download