Skip to content

Instantly share code, notes, and snippets.

@nsoojin
Last active October 26, 2019 09:05
Show Gist options
  • Save nsoojin/93f0dcd9464cf9cff6516c095723e106 to your computer and use it in GitHub Desktop.
Save nsoojin/93f0dcd9464cf9cff6516c095723e106 to your computer and use it in GitHub Desktop.
SharedDefaults Property Wrapper
@propertyWrapper
struct SharedDefault<T> {
let key: String
let defaultValue: T
var wrappedValue: T {
get {
UserDefaults.securityCard.object(forKey: key) as? T ?? defaultValue
}
set {
UserDefaults.securityCard.set(newValue, forKey: key)
}
}
}
//somewhere
extension UserDefaults {
static let securityCard = UserDefaults(suiteName: "...")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment