There seems to be a weird issue with iOS playgrounds, where NSUserDefaults always returns nil instead of the actual value.
On an iOS playground, the last line erroneously returns nil .
import UIKit let defaults = NSUserDefaults.standardUserDefaults() defaults.setObject("This is a test", forKey: "name") let readString = defaults.objectForKey("name")
On an OSX playground, the last line correctly returns "This is a test."
import Cocoa let defaults = NSUserDefaults.standardUserDefaults() defaults.setObject("This is a test", forKey: "name") let readString = defaults.objectForKey("name")
Any idea why this is? Mistake?
ios xcode swift swift-playground nsuserdefaults
Daniel
source share