Ryu Eutsugu Ryu Eutsugu - 2 months ago 11
iOS Question

NSMutableArray that was able to unwrapped in Swiift2.2 becomes nil in Swift2.3

As the title says the Array that could unwrapped in Swift2.2 turns to nil in Swift2.3(xcode8).

it happens in iOS10. Does somone knows the reason?

the self.dataObject is a json dictionary

var array : NSMutableArray?

override func viewDidLoad(){
array = (self.dataObject as! NSDictionary)["array"] as? NSMutableArray
print(array)
}


when i printed self.dataObject

Optional({
attitude = 30;
array = (
{
attendance = "test1";
bring = "test2";
"id" = 503;
},
{
attendance = "test1";
bring = "test2";
"id" = 504;
}
{
attendance = "test1";
bring = "test2";
"id" = 505;
}
);
second_id = n;
})

Answer

I think the array is immutable in this case. Therefore, it would be necessary to init a new mutable array from an immutable one.

Ex. array = NSMutableArray(array: ((self.dataObject as NSDictionary)["array"] as? NSArray)!)

Comments