user3798602 user3798602 - 1 year ago 77
Swift Question

saving key and value pairs swift

I need a way to save key and value pairs in swift for my application. I am new to IOS programming, but I know Android and I am looking for something like shared preferences in android, but for swift. By "save," I mean that when the user quits out of the application, the key and value pairs are saved in the local data.

Answer Source

What you are looking for is called "Userdefaults" - you can use them like this:

Saving Data:

let userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setObject(variable, forKey: "yourKey")

Reading Data:

if let yourVariable: AnyObject = NSUserDefaults.standardUserDefaults().objectForKey("yourKey") {

Here you find more information:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download