Working with NSUserDefaults in Swift 2

I was quite pleased to see than in Swift is even easier than in Objective-C. Here is how you do it:

Create a variable that can access them: 

 

    var userDefaults = NSUserDefaults.standardUserDefaults()

 

Add values to dictionary:

 

    userDefaults.setObject(“StringText”, forKey: “KeyInDictionary”)

 

Read values from dictionary:

 

    

    let textuserDefaults.objectForKey(“KeyInDictionary”) as! String

 

 

And that’s in a very simple way how it works. If you want to get into it deeper you can look into the documentation or read this great post

 

If you have any feedback I’m at @MarcMasVi

Marc