How can I set the default values for "NSUserDefaults"

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

How can I set the default values for "NSUserDefaults"

Post 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")
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

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

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply