Using NSUserDefaults how to save a key before launching an application

I have an application where I need a BOOL value to continue running.

The value should be YES on first start and customization after that.

But if this is the first run, how to set the default value to YES before starting the program?

+3
source share
2 answers

You need to register the default dictionary with NSUserDefaults every time your application starts:

NSDictionary *defaultValues = [NSDictionary dictionaryWithObject:
    [NSNumber numberWithBool:YES] forKey:@"myUserDefaultsKey"];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];

Now,

[[NSUserDefaults standardUserDefaults] boolForKey:@"myUserDefaultsKey"];

will return YES if the key is missing.

+6
source

plist . ( ), plist ...

+2

Source: https://habr.com/ru/post/1736474/


All Articles