How to insert object already existing objects in N

2019-08-21 06:46发布

问题:

I am getting a problem, while inserting an object into the main List.

[editContactList addObject:editcontacts];
[editObject.contactList insertObject:editContactList atIndex:0];//error as mutating method sent to immutable object
[editcontacts release];

回答1:

If you get that particular error, you don't actually have an NSMutableArray; you have an NSArray. Which is immutable. (Note that simply casting an NSArray to NSMutableArray does nothing, the array itself needs to be an instance of a mutable array, rarely seen with instance variables, especially those made accessible publicly.)

Edit: We're going to need some more information; how are these variables defined, how are they initialized, etc.