Skip to content

Commit 43ea33e

Browse files
Merge pull request #10 from GoodRequest/fix/keychain-value-subject
fix: Keychain Value Subject
2 parents fc8301e + 55c4810 commit 43ea33e

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

Sources/GoodPersistence/KeychainValue.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ public class KeychainValue<T: Codable & Equatable> {
228228
// If the new value is equal to the default value, remove the corresponding entry from the Keychain.
229229
do {
230230
try keychain.remove(key)
231+
valueSubject.send(newValue)
231232
} catch {
232233
GoodPersistence.log(message: "Setting keychain value [\(defaultValue)] for key [\(key)] not performed. Reason: Removing from keychain failed.")
233234
throw error
@@ -239,15 +240,11 @@ public class KeychainValue<T: Codable & Equatable> {
239240
do {
240241
// Encoding the wrapped value.
241242
let data = try JSONEncoder().encode(wrapper)
242-
do {
243-
// Storing data in the Keychain using the specified key
244-
try keychain.set(data, key: key)
245-
} catch {
246-
GoodPersistence.log(message: "Setting keychain value [\(defaultValue)] for key [\(key)] not performed. Reason: Data encoding failed.")
247-
throw error
248-
}
243+
// Storing data in the Keychain using the specified key
244+
try keychain.set(data, key: key)
245+
valueSubject.send(newValue)
249246
} catch {
250-
GoodPersistence.log(message: "Setting keychain value [\(defaultValue)] for key [\(key)] not performed. Reason: Data encoding failed.")
247+
GoodPersistence.log(message: "Setting keychain value [\(newValue)] for key [\(key)] not performed. Reason: Data encoding failed.")
251248
throw error
252249
}
253250
GoodPersistence.log(message: "Keychain Data for key [\(key)] has changed to \(newValue).")

0 commit comments

Comments
 (0)