Reputation: 1394
I have a custom object and NSMutableArray as instance member. I fill the array with some data after creation. I need a method to replace the content of the array. I tried:
-(void)replaceArr:(MyClass*) obj
{
[mList removeAllObjects];
NSMutableArray * tempArr=[obj mList];
mList=[NSMutableArray initWithArray:tempArr];
}
But it is failed on
mList=[NSMutableArray initWithArray:tempArr];
Upvotes: 1
Views: 2139
Reputation: 6878
Instead of +alloc-init
ing another NSMutableArray
, you could also just replace the contents of this one by first removing all the objects it contains, and then adding the new ones to it:
- (void)replaceArr:(MyClass *)obj {
[mList removeAllObjects];
[mList addObjectsFromArray:[obj mList]];
}
Upvotes: 3
Reputation: 18741
I think you mean [[NSMutableArray alloc] initWithArray:tempArr];
Upvotes: 0