Skip to content

Instantly share code, notes, and snippets.

@LeeKahSeng
Last active October 19, 2019 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeeKahSeng/0e1bf5ef92a7b8925dbd8f6c22a77f1a to your computer and use it in GitHub Desktop.
Save LeeKahSeng/0e1bf5ef92a7b8925dbd8f6c22a77f1a to your computer and use it in GitHub Desktop.
struct AppData {
private static let enableAutoLoginKey = "enable_auto_login_key"
private static let usernameKey = "username_key"
static var enableAutoLogin: Bool {
get {
// Read from UserDefaults
return UserDefaults.standard.bool(forKey:enableAutoLoginKey)
}
set {
// Save to UserDefaults
UserDefaults.standard.set(newValue, forKey: enableAutoLoginKey)
}
}
static var username: String {
get {
// Read from UserDefaults
return UserDefaults.standard.string(forKey: usernameKey) ?? ""
}
set {
// Save to UserDefaults
UserDefaults.standard.set(newValue, forKey: usernameKey)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment