Create a Settings Bundle for iOS with Swift

Written on:August 6, 2014
Add One

Here are some quick little code tips for creating a settings bundle in Swift for iOS.

Settings are very easy to setup for iOS. Just note that the simulator currently does not work with settings correctly. The code in this post does work just fine on a device.

Load the Defaults into the Settings:

let appDefaults = [SettingsKeys.namePreferenceKey: "Default Name"]

Get the Settings value:

var namePreference = NSUserDefaults.standardUserDefaults().stringForKey(SettingsKeys.namePreferenceKey)

Save the Settings value:

NSUserDefaults.standardUserDefaults().setValue(namePreferenceField!.text, forKey:SettingsKeys.namePreferenceKey)

Here is the source code for this Swift project:
CreateSettings Xcode Project

Leave a Comment

Previous post: