Last active
December 21, 2019 03:25
-
-
Save hlung/ccc84b5d4962b1b05b81a88076e75886 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct UserSettings: Codable { | |
let someBool: Bool | |
let someDate: Date | |
} | |
var userSettings: UserSettings? { | |
get { | |
guard let data = UserDefaults.standard.object(forKey: "userSettings") as? Data else { return nil } | |
return try? JSONDecoder().decode(UserSettings.self, from: data) | |
} | |
set { | |
UserDefaults.standard.set(try? JSONEncoder().encode(newValue), forKey: "userSettings") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment