Re: [iOS] NSUserDefaults best practices
Re: [iOS] NSUserDefaults best practices
- Subject: Re: [iOS] NSUserDefaults best practices
- From: Matt Neuburg <email@hidden>
- Date: Sat, 5 Feb 2011 14:46:51 -0800
On Sat, 05 Feb 2011 07:33:08 -0500, Philip Vallone <email@hidden> said:
>Hi,
>
>After some reading I understand that when creating a Settings Bundle for by iOS app, that I need to explicitly set the defaults.
You don't *have* to; the settings bundle itself specifies your default defaults. It must, since otherwise if the user summons your bundle through the Settings app, how will the Settings app know what default values to give your defaults? The Settings app will register those values into the shared user defaults for you. The only reason you need to set default defaults in the app itself is in case the Settings app hasn't run. But, of course, it might not, so it's good practice.
>I decided to use a singleton to set my defaults settings. When the application is launched, I initiate the singleton from the didFinishLaunchingWithOptions in my App Delegate.
NSUserDefaults' standardUserDefaults *is* a singleton. Just call registerDefaults: in didFinishLaunching... and you're done. (There is no need, in iOS, to do it any earlier, as with +initialize, because there are no bindings in iOS.) m.
--
matt neuburg, phd = email@hidden, <http://www.apeth.net/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.apeth.net/matt/default.html#applescriptthings_______________________________________________
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