Re: NSUserDefaults not sticking
Re: NSUserDefaults not sticking
- Subject: Re: NSUserDefaults not sticking
- From: Scott Ribe <email@hidden>
- Date: Wed, 10 Sep 2014 20:04:03 -0600
On Sep 10, 2014, at 6:42 PM, Graham Cox <email@hidden> wrote:
> Then you should be fine. The point is that the .plist does not necessarily represent the current state of the defaults for your app. Trashing it for example no longer resets the defaults like it used to, you have to go through the defaults system to reset them (as Kyle pointed out).
Interesting point here... I was recently trying to debug some things I was doing with NSUserDefaults (stuffing printer settings into flattened XML apparently coded as Base64), and ran across the problem that the .plist is not updated when you sync, so I was unable to look at the plist to confirm what was actually being stored, which made debugging significantly more obtuse.
The real point: plenty of sites on the web state that the .plist no longer represents the current state, but that the defaults command will read the current state so you can use it for debugging. They are wrong. Apparently there's something about the caching such that defaults, and I expect any other process outside the one making the changes, DOES NOT return the latest values you synched. It is absolutely the case that your app can use NSUserDefaults to update defaults, can synch them, can then read back the new values and confirm that NSUserDefaults is returning the latest values you gave it, and the defaults command line will at that point still be returning stale values from before your update.
Now, whether this differs depending on whether or not you're running under the debugger, I didn't check. I figured out my bug and fixed it before I got to that point ;-)
But basically, this is now a royal PITA to debug, because there does not seem to be ANY way to externally confirm what your program has written into the defaults db.
--
Scott Ribe
email@hidden
http://www.elevated-dev.com/
(303) 722-0567 voice
_______________________________________________
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