We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Like AppStorage, we can make a custom UserDefaults property wrapper that conforms to DynamicProperty
@propertyWrapper public struct UserDefault<Value>: DynamicProperty { @State private var value: Value let key: String let store: UserDefaults public init( wrappedValue: Value, _ key: String, store: UserDefaults = .standard ) { self.key = key self.store = store let value = (store.object(forKey: key) as? Value) ?? wrappedValue self._value = State(wrappedValue: value) } public var wrappedValue: Value { get { value } nonmutating set { store.set(newValue, forKey: key) value = newValue } } public var projectedValue: Binding<Value> { .init( get: { wrappedValue }, set: { wrappedValue = $0 } ) } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Like AppStorage, we can make a custom UserDefaults property wrapper that conforms to DynamicProperty
The text was updated successfully, but these errors were encountered: