user2924482 user2924482 - 11 months ago 78
iOS Question

Swift: Is not saving NSUserDefaults.standardUserDefaults values

I'm trying to save key value in the NSUserDefaults but is not been save. Here is my code:

func saveData() {

let userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setObject("blablabla", forKey:"data")

Any of you knows why this data is not been save?

I'll really appreciate your help.


According with Apple sources:

public func valueForKey(key: String) -> AnyObject?

to retrieve your value you could use:

if let value = userDefaults.valueForKey("data")  {
    // do whatever you want with your value
    // P.S. value could be numeric,string,..