Why use registerDefaults: instead of setValue: forKey :?

When I configure the default settings for my application, I do the following:

1) Reading Root.plistfrom the inside Settings.bundleinto a dictionary.

2) I check if preference is set, and if not, I register the default dictionary through [NSUserDefaults standardUserDefaults] registerDefaults:]

The problem is that the default values ​​registered with help registerDefaults:do not go into persistent storage, so if the user never changes his preferences, I read my default settings and register them with NSUserDefaultsevery time the application starts.

Instead of using it, registerDefaults:I could use it setValue:forKey:, and my default setting is to persistent storage, bypassing the need to create and register a dictionary every time I start. However, Apple documentation and sample code point to registerDefaults:.

So, I'm trying to figure out when and why should I use registerDefaults:, and when / why should I use setValue:forKey:instead?

+5
source share
1 answer

, registerDefaults: , , , NSUserDefaults , .

. ? , ?

registerDefaults: setValue: forKey: , . Apple registerDefaults:.

" ? ? OK, ". , registerDefaults:.

registerDefaults: . setValue:forKey: .

, NSUserDefaults Mac. defaults, , .

+5

All Articles