我想将NSMutableArray的addObject添加到NSMutableArray中,所以我该如何在
swift中实现这一点.
并检索它所以请帮助我,因为现在我正在学习迅速.
并检索它所以请帮助我,因为现在我正在学习迅速.
间接地说我想要2D数组意味着NSMutableArray的NSMutableArray.
//The below 2 lines iterative! var dict:NSMutableDictionary? = NSMutableDictionary(); linePointsArray!.addObject(dict!); // and below 2 line is execute after complete the above iteration arrLine!.addObject(linePointsArray!); linePointArray!.removeAllObject(); //after that the above whole process is done iterative.
解决方法
如果我没有错,你想在另一个NSMutableArray中添加一个NSMutableArray的对象,你可以通过以下代码来实现
var myArray : NSMutableArray = ["Hello"] var arrayOfArray : NSMutableArray = [myArray] // Insert more arrays with insertObject or addObject arrayOfArray.insertObject(myArray,atIndex: 0) arrayOfArray.addObject(myArray) //Retrive var newArray:NSMutableArray = arrayOfArray[0] as NSMutableArray println("\(newArray)")
对于Swift 3:
var myArray : NSMutableArray = ["Hello"] var arrayOfArray : NSMutableArray = [myArray] // Insert more arrays with insertObject or addObject arrayOfArray.insert(myArray,at: 0) arrayOfArray.add(myArray) //Retrive var newArray:NSMutableArray = arrayOfArray[0] as! NSMutableArray print("\(newArray)")