user2924482 user2924482 - 1 year ago 135
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.

Answer Source

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,..
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download