Simple way to store integer preference?

Ok, I’ve tried a bunch of examples on here, but I just can’t get it to work. Could someone please post a quick step-by-step instruction on how to store and recall a preference of an integer, let’s say it’s called “r1Feet”? This integer value is bound to a text field, so I can’t use bindings for the preferences. I seem to be missing something obvious, but I just can’t get it to work. This is what I have tried so far:

I put this in my applicationWillFinishLaunching_:

		
tell current application's NSUserDefaults to set defaults to standardUserDefaults()
tell defaults to registerDefaults_({r1FeetKVC:9998})

Then I call this method in my applicationWillFinishLaunching_:


	on retrieveDefaults_(sender)
		tell defaults to set r1Feet to integerForKey_("r1FeetKVC")
end retrieveDefaults_

Then I try to call this method in my applicationShouldTerminate_, but if I put the call in there, the application won’t quit.


	on saveDefaults_(sender)
tell defaults to setInteger_forKey_(r1Feet, "r1FeetKVC")
	end saveDefaults_

Please help. Thanks so much. :slight_smile:

Try using objectForKey instead of integerForkey, and see what happens. AS integers don’t get sent as integers anyway – they get converted to NSNumber objects.

I tried that first actually, and it didn’t work. If I call either the retrieve or save, it actually hangs my code. Something is missing from this puzzle.

I’m presuming defaults is a property.

Try throwing out the .plist file and trying again – I’ve found that experimentation can sometimes get them into a bit of a state…

Do you have r1Feet declared as a property too?

Ric