Re: Array of dictionaries + NSUserDefaultsController
Re: Array of dictionaries + NSUserDefaultsController
- Subject: Re: Array of dictionaries + NSUserDefaultsController
- From: Brent Gulanowski <email@hidden>
- Date: Thu, 21 Oct 2004 17:37:47 -0400
On Thu, 21 Oct 2004 14:05:01 -0400, Brent Gulanowski
<email@hidden> wrote:
>
Hi,
>
>
I just read through this thread in the archives:
>
>
http://www.cocoabuilder.com/archive/message/cocoa/2003/12/23/75669
>
>
but it discusses the inverse of what I'm finding so I'd be thankful to
>
have my error pointed out.
>
>
Supposedly stuff coming back from user defaults is mutable, although
>
that's not what I'm experiencing with NSArrayController tied to an
>
array of dictionaries in NSUserDefaults. Existing elements, supposedly
>
immutable, are easily changeable. (I naively thought, previously, that
>
this depended on how I saved the array the first time, so I made the
>
array and the contained dictionaries mutable. Also, changing it from
>
immutable to mutable fixed an earlier problem ... is the info in that
>
discussion out of date?) This is not my problem.
>
>
My problem is that I'm adding to the array and trying to change the
>
new dictionary. But then I get the classic error: "-[NSCFDictionary
>
setObject:forKey:]: mutating method sent to immutable object". That's
>
confusing because I just created that new dictionary with
>
-[NSArrayController add:], and the controller's object setting is
>
"NSMutableDictionary".
>
>
This was working previously and I changed something you'd think was
>
unrelated, and now it's not working.
>
>
Thanks in advance.
>
I figured it out.
If you turn off immediate saving with a -[NSUserDefaultsController
setSavesImmediately:] with a "NO" argument, the array members behave
like mutable dictionaries. This is a *very strange* side effect.
Changes performed in the settings dialog in question when
savesImmediately is NO are happily saved to the preferences plist when
it's changed back to YES. I'm interested if there's any connection
between this and the other problem I noted (without response) about
-[NSUserDefaultsController save:] saving defaults from the
registration domain in the prefs plist as well (which I think is a bug
since it's inconsistent with the behaviour of NSUserDefaults -- Radar
3848937).
My problem surfaced when my window's delegate (file's owner, a window
controller) got disconnected, perhaps when I changed the class (if
that's true, it's another weird side effect). I was calling
setSavesImmediately: on window becoming key (set it to "NO") and
resigning key (set it to "YES") notifications, which stopped coming
through when the delegate got disconnected.
--
Brent Gulanowski
http://www.boredastronaut.com
_______________________________________________
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