Ok, so I'm relatively new to Objective-C, but not to programming. I have set up an NSMutableArray to hold a collection of objects, that I want to add and remove from. So in my interface:
if I try to add or remove objects from this array I get an exception:
"mutating method sent to immutable object"
I can get around this by copying the array adding my object, and then assigning the pointer to the new object, but this just seems silly.
I figure I must be doing something rather stupid. Can someone give me any pointers about this?
Code:
NSMutableArray *savedLocations;
if I try to add or remove objects from this array I get an exception:
"mutating method sent to immutable object"
I can get around this by copying the array adding my object, and then assigning the pointer to the new object, but this just seems silly.
Code:
NSMutableArray *test = [savedLocations mutableCopy];
[test addObject:location];
self.savedLocations = test;
[test release];
I figure I must be doing something rather stupid. Can someone give me any pointers about this?