NSMutableArray is immutable when unarchived
NSMutableArray is immutable when unarchived
- Subject: NSMutableArray is immutable when unarchived
- From: nick briggs <email@hidden>
- Date: Fri, 15 Jul 2005 11:02:13 +0100
Hi
I have a NSMutableArray which I routinely add objects to. This works
fine until I encode / decode the array with NSCoder, as shown below.
The problem is when I now try to add an object with:
[_triggers addObject:trigger];
I get he error:
[NSCFArray addObject:]: mutating method sent to immutable object
What's up?
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NSMutableArray *_triggers;
- (id)initWithObject:(id)anObject
{
if(self = [super init])
{
...
_triggers = [[NSMutableArray array]retain];
...
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
...
_triggers = [[aDecoder decodeObjectForKey:kTriggers]retain];
...
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
...
[aCoder encodeObject:_triggers forKey:kTriggers];
...
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cheers
Nick
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden