Re: NSArrayController with User Defaults
Re: NSArrayController with User Defaults
- Subject: Re: NSArrayController with User Defaults
- From: Nick Zitzmann <email@hidden>
- Date: Fri, 16 Apr 2004 07:37:05 -0600
On Apr 16, 2004, at 3:38 AM, Johan Kool wrote:
In the same simple app I am trying to get the content of a
NSArrayController saved into the user defaults. This seems to work
when I test my interface in IB, but when I do it in my own app I get
this error:
*** -[NSCFDictionary setObject:forKey:]: mutating method sent to
immutable object
You can't send -setObject:forKey: to an immutable dictionary or else it
will raise the above exception. Just because you declare something to
be an NSMutableDictionary doesn't mean it is a mutable dictionary; if
you call something that returns an NSDictionary, and treat it like a
mutable dictionary, then you'll run into problems like the above.
Instead, you need to do this:
NSMutableDictionary *someDictionary = [[someOtherDictionary
mutableCopy] autorelease];
Then someDictionary will be a mutable copy of someOtherDictionary, and
you can use that. But if your intention is to set some keys in a
dictionary obtained from the user defaults, then you'll need to
remember to put the dictionary back into the user defaults when you're
done making changes.
Nick Zitzmann
<
http://www.chronosnet.com/>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.