I added a Settings bundle to my app and in Xcode it appears in the root of my project tree view.
The Root.plist
file looks like this:
&l
Apparently the cause is that if my settings in the plist
have defaults defined and the user has not explicitly set a value, then the value displayed in the Settings app will be the defaults from the plist
file, however the NSUserDefaults
API will still return nil
.
Unfortunately this means that if the default value is meaningful (such as a default web-service address URI: "http://www.example.com
") it must exist twice in my project: as a default in the plist
and in my program code:
Root.plist:
Key mySettingKey
Title Some address
Type PSTextFieldSpecifier
DefaultValue http://www.example.com
IsSecure
KeyboardType Alphabet
Program.swift:
let ud = NSUserDefaults.standardUserDefaults()
ud.synchronize()
var mySettingValue = ud.stringForKey("mySettingKey")
if mySettingValue == nil {
mySettingValue = "http://www.example.com"
}
That's surprising.