0

So I was reading this: Storing iPhone application settings in app which seems simple enough.

However, where/how would I define the initial settings?

So for instance I have a Country setting: UK or USA. When the app is first installed/opened I want it to automatically know/set NSUserDefaults to UK.

I hope this is clear ha.

Tom

Community
  • 1
  • 1
Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224

1 Answers1

2

You can use the -registerDefaults: method to set up the "default defaults":

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/UserDefaults/Tasks/UsingDefaults.html#//apple_ref/doc/uid/20000719-BAJFBAAH

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
  • this seems ok, except I'm worried that if a user closes the app and then reopens it will it "reset" the settings? ie: if a user installs the app and changes their country to US I want it to remember that indefinitely. Will this work for that? – Thomas Clayson Aug 25 '10 at 15:01
  • 1
    I find the nomenclature in the API confusing. Registering defaults means providing actual default values. Anything you store in "standardUserDefaults" though should take precedence over the default-default. It's easy enough to test to reassure yourself. :) – Ben Zotto Aug 25 '10 at 15:53