User defaults and bindings - when are the values actually written?

I have a number of fields in a preferences window which I bound to “Shared User Defaults” in IB.

In “Application Will Finish Launching”, I registered some user defaults:
tell current application’s NSUserDefaults to set defaults to standardUserDefaults()
tell defaults to registerDefaults_({thing:“value”, thing2:“value2”})

This all works fine. The problem I’m now having is that I change the preference values, and they aren’t always saved between restarts.

How can I ensure these get written? I do have an “apply” method for my preferences, so I could do it there, I just wasn’t sure how to do it.

Have a look at synchronize in the Docs.

Also wrong or right, I normally have ‘Continuously Update’ checked in the bindings in IB

How do you change them?

I just change them via a preferences pane. One is a Radio Matrix, the others are all text fields.

if you changed them in the UI and the bindings are correct, they will be written. If they aren’t, chances are it’s a bindings problem.

Hmm, that’s annoying.

I just clicked “bindto” “Shared User Defaults Controller”, and set the model key value (for the values).

It’s odd that it’s working some of the time, but not all of the time.

Add a button somewhere and connect it to a handler that logs the values of the defaults you’re changing. Then exercise your UI, and hit the new button each time to see what is and isn’t working.

For text fields, if you don’t have Continuously Updates checked, you need to make sure that any changes are committed.

Ugh so ridiculous, I was missing continuously updated.

I was looking at the options for Radio Matrix, where it doesn’t appear, so I didn’t go back and check the other fields as well. It seems to be working great now!

Now some product help, a website, and I should be good to ship.