Last active
December 21, 2019 03:25
Star
You must be signed in to star a gist
This file contains 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