How to addObject as NSMutableArray in NSMutableArray in swift
If I am not wrong you want to add an object of NSMutableArray in another NSMutableArray you can do it by following code
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)")
For 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)")
Here is an example:
var mutableArray: NSMutableArray = []
var nestedMutableArray: NSMutableArray = []
mutableArray.addObject(nestedMutableArray)
var retrievedNestedMutableArray:NSMutableArray = mutableArray[0] as NSMutableArray