Showing posts with label NSMutableArray. Show all posts
Showing posts with label NSMutableArray. Show all posts

Thursday, March 1, 2012

Tips for deep copy of NSMutableArray

Ok, So if you want to create a deep copy of NSMutableArray which contains items of custom class, you can refer to my old previous post HERE.

But here is the thing if your NSMutableArray contains the non custom class contains like NS(Mutable)Dictionary, you WONT be able to create deep copy by simple doing:


NSMutableArray *a= [[NSMutableArray alloc]initWithArray:b];



Rather,  you can do following trick:

NSMutableArray *a = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:b]];

For simple copy of array, you can read POST HERE.


Thursday, June 16, 2011

Copy items of NSMutableArray into another ?

Lets say you have arrayA and arrayB, arrayB could be NSArray or NSMutableArray.
But arrayA should be mutable.


  [arrayA addObjectsFromArray:arrayB];





Here you are copying items from  arrayB to arrayA. Make sure you have already alloc memory for arrayA as:

arrayA = [[NSMutableArray alloc]init];




Case 2: If you want to create a copy an array to NSArray, you can do so as following:

NSArray *db=[[NSArray alloc]initWithArray:availListArray];