Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.