There seems to be a strange issue with iOS Playgrounds where NSUserDefaults
always returnsnil
instead of the actual value.
In an iOS Playground the last line wrongly returns nil
.
import UIKit
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject("This is a test", forKey: "name")
let readString = defaults.objectForKey("name")
In 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? Bug?