Page 1 of 1

How can I set the default values for "NSUserDefaults"

Posted: Wed Jul 17, 2019 11:52 am
by Wolfram
How can I detect if the program is running the first time an I have to initialize the default values?

In this example here I can see how to use the "NSUserDefaults standardUserDefaults", but how can I set the standard value if the Preferences file is generated.
viewtopic.php?p=404904#p404904

In PB it is simple

Code: Select all

ReadPreferenceString("myParameter", "standardValue")

Re: How can I set the default values for "NSUserDefaults"

Posted: Wed Jul 17, 2019 6:49 pm
by wilbert
The NSUserDefaults class has a method called registerDefaults: that allows you to set default values.
Most examples use a plist file where you put the default values, parse that file and use the resulting dictionary for the registerDefaults: method.