Skip to content

Instantly share code, notes, and snippets.

@ihamadfuad
Created February 21, 2022 07:11
Show Gist options
  • Save ihamadfuad/045e03cb79bc996d3b50a3a4fbf46607 to your computer and use it in GitHub Desktop.
Save ihamadfuad/045e03cb79bc996d3b50a3a4fbf46607 to your computer and use it in GitHub Desktop.
var wrappedValue: Value? {
get { value }
nonmutating set {
value = newValue
do {
let encoded = try JSONEncoder().encode(value)
try Keychain().set(encoded, key: key)
} catch let error {
try? Keychain().remove(key)
}
}
}
var projectedValue: Binding<Value?> {
Binding(get: { wrappedValue }, set: { wrappedValue = $0 })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment