mnort9
mnort9

Reputation: 1820

NSUserDefaults intitial setup

I'm saving a few user settings in NSUserDefaults. If these settings have not been modified by the user, I'd like the app to use presets.

How should I set this up so the app first checks if settings have been modified and if not, sets presets?

Checking if [[NSUserDefaults standardDefaults]objectForKey: @"setting1"] == nil ? Then setting a preset if it is not?

Upvotes: 0

Views: 142

Answers (2)

Alex Wayne
Alex Wayne

Reputation: 187004

[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html#//apple_ref/doc/uid/20000318-CIHDDCDB

Call that from your applicationDidFinishLaunchingWithOptions: method that sets up whatever defaults you may need.

Upvotes: 4

rdelmar
rdelmar

Reputation: 104082

Look at the NSUserDefaults docs for registerDefaults. This allows you to have default values until the user changes them, then they have no effect.

Upvotes: 0

Related Questions