I’ve made my first foray into user defaults, and have found what seems to be a problem with bindings and user defaults - i don’t know if this is something I’m doing wrong, or this is a bug. I tried Shane’s program, User defaults_stuff, and sometimes the changes I make to the top UI elements (the ones that use bindings to the User Defaults Controller) show up and sometimes they don’t. Watching the plist file in finder, I can see that it is not updated immediately, even though the documentation says that updating changes immediately is the default setting for the controller (I tried setting that property explicitly, and that didn’t make any difference). This doesn’t seem to be a problem if you use NSUserDefaults in code and call synchronize() on your instance of the standardUserDefaults --that updates the plist file immediately.
The values written to disk periodically, not instantly, and on quit. You can call synchronize() on the controller to force a write, but I’m curious why you would want to.
I was not seeing the values written to disk on quit – that’s how I was testing it. I would change some values, quit the program then restart. Sometimes I would see the changes when I restarted and sometimes not. Could this be an artifact of how I’m quitting the program (by clicking on the stop sign in the Xcode window)?
I need to if I make a change just before quitting, and the write on quit is not working --of course if write on quit works, then I have no need to call synchronize.
Yeah, that was it --I did some more experimenting, and quitting the program with a command-q or adding a applicationShouldTerminateAfterLastWindowClosed method (and changing your window to make it closable) both resulted in immediate writing of the values to disk.