Skip to content

Commit 9379e6a

Browse files
authored
Merge pull request #78 from mergesort/dynamic-property
Fixes Views not updating when a StoredValue or SecurelyStoredValue updates
2 parents 808ce09 + e26fe2e commit 9379e6a

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

Demo/Demo/Components/FavoritesCarouselView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private extension FavoritesCarouselView {
126126
})
127127

128128
Button(action: {
129-
self.appState.funkyRedPandaModeEnabled.toggle()
129+
self.appState.$funkyRedPandaModeEnabled.toggle()
130130
}, label: {
131131
Image(systemName: "sun.max.circle.fill")
132132
.opacity(self.images.isEmpty ? 0.0 : 1.0)

Sources/Boutique/SecurelyStoredValue.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import Observation
3+
import SwiftUI
34

45
/// The @``SecurelyStoredValue`` property wrapper automagically persists a single `Item` in the system `Keychain`
56
/// rather than an array of items that would be persisted in a ``Store`` or using @``Stored``.
@@ -50,7 +51,7 @@ import Observation
5051
@MainActor
5152
@Observable
5253
@propertyWrapper
53-
public final class SecurelyStoredValue<Item: StorableItem> {
54+
public final class SecurelyStoredValue<Item: StorableItem>: DynamicProperty {
5455
private let observationRegistrar = ObservationRegistrar()
5556
private let valueSubject = AsyncValueSubject<Item?>(nil)
5657

Sources/Boutique/StoredValue.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import Observation
3+
import SwiftUI
34

45
/// The @``StoredValue`` property wrapper to automagically persist a single `Item` in `UserDefaults`
56
/// rather than an array of items that would be persisted in a ``Store`` or using @``Stored``.
@@ -55,7 +56,7 @@ import Observation
5556
@MainActor
5657
@Observable
5758
@propertyWrapper
58-
public final class StoredValue<Item: StorableItem> {
59+
public final class StoredValue<Item: StorableItem>: DynamicProperty {
5960
private let observationRegistrar = ObservationRegistrar()
6061
private let valueSubject: AsyncValueSubject<Item>
6162
private let cachedValue: CachedValue<Item>
@@ -95,7 +96,7 @@ public final class StoredValue<Item: StorableItem> {
9596

9697
/// The currently stored value
9798
public var wrappedValue: Item {
98-
self.cachedValue.wrappedValue
99+
self.retrieveItem()
99100
}
100101

101102
/// A ``StoredValue`` which exposes ``set(_:)`` and ``reset()`` functions alongside an `AsyncStream` of ``values``.

0 commit comments

Comments
 (0)