Re: Problem with NSUserDefaultsController
Re: Problem with NSUserDefaultsController
- Subject: Re: Problem with NSUserDefaultsController
- From: Brian Stern <email@hidden>
- Date: Mon, 1 Sep 2008 16:22:14 -0400
Apparently NSUserDefaults delays its saving until the next time
through the event loop, perhaps by using one of the
performSelector:afterDelay calls, or something like that. Is it
possible that this is what's causing your issues?
I ran into this problem when trying to save user defaults at app
terminate time, when afterDelay never comes.
On Sep 1, 2008, at 4:07 PM, Mark Allan wrote:
>> I've been playing around with bindings to
NSUserDefaultsController in
a very simple app to test saving preferences, but the
[sharedUserDefaultsController save:self] method seems to return
immediately
without waiting for the save operation to complete.
The save does actually take place, which I can see if I open the
plist file
in Property List Editor, but if the very next line after sending
the save
message is one which reads a property from the plist, it's the
old value
which gets returned rather than the newly saved one.
The -save: method is unintuitive in name. It does not, as you
may think,
save changes to disk. It simply commits any changes to the
NSUserDefaults
object. It's a no-op if appliesImmediately is YES. The only way
to force a
save is to call -synchronize on NSUserDefaults.
Thanks but the problem is actually the exact opposite. The file
IS being
saved - it's the userdefaults object which doesn't contain the
right value
unless there's some short delay between the save and objectForKey
messages.
Sorry, I misread your post. We will need to see some code to
determine the
issue.
Calling -synchronize on the userDefaults object makes no difference.
I'm already setting appliesimmediately to YES so that I can have
Cancel and OK buttons, and in terms of saving/reverting the plist
file
it's working fine. Do I need to perform some action to connect the
userdefaults object to the userDefaultsController object?
Well, not other than binding it to the shared user defaults (unless
you are
creating it programmatically, where it is set on creation). My
understanding
is that the NSUserDefaults object is responsible for writing to
disk, so if
you get the disk commit, it must be in the shared defaults.
Exactly! That's my understanding too, which is why I'm confused.
The complete Xcode project is available here:
http://idisk.mac.com/markallan-Public/TestingNSUserDefaultsController.zip
If anyone has time to cast an eye over it, I'd really appreciate it.
Thanks
_______________________________________________
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