Swift NSMutableArray add one more array

吃可爱长大的小学妹 提交于 2019-12-02 01:02:52

You should create a mutable array from immutable. This:

ary_mutable=jsonResult as AnyObject as! NSMutableArray

does not do it, it is just a static cast from one type to another. You have to construct a new NSMutableArray and then fill it with required values.

Change your code to

var ary_mutable = NSMutableArray()

// everytime you receive a new data
ary_mutable.addObjectsFromArray(jsonResult as! [AnyObject])

replace this code:

var myArray :NSArray!
myArray = jsonResult as AnyObject as! NSArray
ary_mutable.addObject(myArray.objectAtIndex(0))

with this code:

var myArray : NSMutableArray!
myArray = jsonResult as AnyObject as! NSMutableArray
ary_mutable.addObjectsFromArray(myArray as [AnyObject]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!