Skip to content

Commit f0c4629

Browse files
committed
Fix SwiftUI views not updating after a change
1 parent 42dbc9b commit f0c4629

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

Sources/SecureStorage/SecureStorage.swift

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ public struct SecureStorage: DynamicProperty {
4747
}
4848

4949
/// The value of the key in the keychain.
50-
public var wrappedValue: String? {
51-
get {
50+
@State public var wrappedValue: String?
51+
52+
/// A binding to the value of the key in iCloud.
53+
public var projectedValue: Binding<String?> {
54+
Binding {
5255
let query = [
5356
kSecAttrService: service,
5457
kSecAttrAccount: key,
@@ -65,10 +68,7 @@ public struct SecureStorage: DynamicProperty {
6568
}
6669

6770
return nil
68-
}
69-
70-
// This needs to be nonmutating because we're setting a property on a struct.
71-
nonmutating set {
71+
} set: { newValue in
7272
if let newValue {
7373
let data = Data(newValue.utf8)
7474
let query = [
@@ -107,17 +107,7 @@ public struct SecureStorage: DynamicProperty {
107107

108108
SecItemDelete(query)
109109
}
110-
}
111-
}
112-
}
113-
114-
/// A binding to the value of the key in iCloud.
115-
public var projectedValue: Binding<String?> {
116-
Binding {
117-
return self.wrappedValue
118-
} set: { newValue in
119-
self.wrappedValue = newValue
120-
}
110+
} }
121111
}
122112

123113
/// Delete the item from the keychain.

0 commit comments

Comments
 (0)