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
You need to manually read the default values from Settings.bundle and add them to the UserDefaults registration domain, which can be done with UserDefaults.register(). By using the registration domain, the values are held in memory (volatile), so calling UserDefaults.synchronize() is not needed.
Here's a few lines of Swift that will get the job done:
// Register the default values from Settings.bundle
if let settingsURL = Bundle.main.url(forResource: "Root", withExtension: "plist", subdirectory: "Settings.bundle"),
let settingsRootDict = NSDictionary(contentsOf: settingsURL),
let prefSpecifiers = settingsRootDict["PreferenceSpecifiers"] as? [NSDictionary],
let keysAndValues = prefSpecifiers.map({ d in (d["Key"], d["DefaultValue"]) }) as? [(String, Any)] {
UserDefaults.standard.register(defaults: Dictionary(uniqueKeysWithValues: keysAndValues))
}