Difference between revisions of "Swift: Use NSUserDefaults to Store Persistence Data"
From Hawk Wiki
(Created page with "<pre class="brush:swift"> //Set data NSUserDefaults.standardUserDefaults().setObject(["settingABC": false], forKey: "settingABC") //Load Data //func objectForKey(defaultName:...") |
|||
Line 5: | Line 5: | ||
//func objectForKey(defaultName: String) -> AnyObject? | //func objectForKey(defaultName: String) -> AnyObject? | ||
let settings = NSUserDefaults.standardUserDefaults().objectForKey("settingABC") as? [String: Bool] | let settings = NSUserDefaults.standardUserDefaults().objectForKey("settingABC") as? [String: Bool] | ||
+ | </pre> | ||
+ | To sync/update NSUserDefaults | ||
+ | <pre class="brush:swift"> | ||
+ | NSUserDefaults.standardUserDefaults().synchronize() | ||
</pre> | </pre> |
Latest revision as of 04:04, 10 April 2015
//Set data NSUserDefaults.standardUserDefaults().setObject(["settingABC": false], forKey: "settingABC") //Load Data //func objectForKey(defaultName: String) -> AnyObject? let settings = NSUserDefaults.standardUserDefaults().objectForKey("settingABC") as? [String: Bool]
To sync/update NSUserDefaults
NSUserDefaults.standardUserDefaults().synchronize()