NSUserDefaults
suggest changeSyntax
UserDefaults.standard.set(dic, forKey: "LoginSession")saves a value.UserDefaults.standard.object(forKey: "LoginSession") as? [String: AnyObject] ?? [:]reads it back.
This is Swift 3. dic must already be a property-list value. UserDefaults stores property-list types such as string, data, date, number, array, and dictionary. The cast has to match what was stored; otherwise the read becomes an empty dictionary.
Remarks
UserDefaults can be read from anywhere in the app. It is not a general object database. NSUserDefaults
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents