Re: *** -[NSCFDictionary setObject:forKey:]: mutating method sent to immutable object
Re: *** -[NSCFDictionary setObject:forKey:]: mutating method sent to immutable object
- Subject: Re: *** -[NSCFDictionary setObject:forKey:]: mutating method sent to immutable object
- From: Bill Bumgarner <email@hidden>
- Date: Tue, 19 Feb 2008 11:46:39 -0800
On Feb 19, 2008, at 11:24 AM, Hamish Allan wrote:
On Feb 19, 2008 6:00 PM, Daniel Child <email@hidden> wrote:
- (id) init
{
data = [[NSMutableDictionary alloc] init];
return self = [super initWithWindowNibName: @"Step1Window"];
}
Always call [super init...] at the start of your init method.
Otherwise, your superclass could be overwriting the ivar called "data"
with, e.g., an immutable NSDictionary.
Hamish is correct in that this should be structured something like:
- init
{
if (self = [super initWithWindowNibName: @"Step1Window"]) {
data = [[NSMutableDictionary alloc] init];
}
return self;
}
Given that you declared the instance variable in the class w/the init,
super better not be replacing your ivar!
So, how could data become a non-mutable object?
(1) Unarchival generally produces immutable objects unless you
explicitly ask for mutable objects.
(2) You released data and replaced it with a reference to an immutable
object
(3) You have a memory munching bug
b.bum
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden