Skip to content

Commit 3d98a76

Browse files
committed
Tweaks
1 parent a6fc06a commit 3d98a76

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Sources/Defaults/Defaults.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ extension Defaults {
285285

286286
continuation.onTermination = { _ in
287287
// `invalidate()` should be thread-safe, but it is not in practice.
288-
DispatchQueue.main.async {
288+
Task { @MainActor in
289289
observation.invalidate()
290290
}
291291
}
@@ -334,7 +334,7 @@ extension Defaults {
334334

335335
continuation.onTermination = { _ in
336336
// `invalidate()` should be thread-safe, but it is not in practice.
337-
DispatchQueue.main.async {
337+
Task { @MainActor in
338338
for observation in immutableObservations {
339339
observation.invalidate()
340340
}
@@ -378,7 +378,7 @@ extension Defaults {
378378

379379
continuation.onTermination = { _ in
380380
// `invalidate()` should be thread-safe, but it is not in practice.
381-
DispatchQueue.main.async {
381+
Task { @MainActor in
382382
for observation in observations {
383383
observation.invalidate()
384384
}

Sources/Defaults/SwiftUI.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ Access stored values from SwiftUI.
7575

7676
This is similar to `@AppStorage` but it accepts a ``Defaults/Key`` and many more types.
7777
*/
78+
@MainActor
7879
@propertyWrapper
79-
public struct Default<Value: Defaults.Serializable>: DynamicProperty {
80+
public struct Default<Value: Defaults.Serializable>: @preconcurrency DynamicProperty {
8081
@_documentation(visibility: private)
8182
public typealias Publisher = AnyPublisher<Defaults.KeyChange<Value>, Never>
8283

@@ -254,8 +255,10 @@ extension Defaults.Toggle {
254255
}
255256
}
256257

258+
@MainActor
257259
@propertyWrapper
258260
private struct ViewStorage<Value>: DynamicProperty {
261+
@MainActor
259262
private final class ValueBox {
260263
var value: Value
261264

Tests/DefaultsTests/DefaultsSwiftUITests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ final class DefaultsSwiftUITests {
4141
Defaults.removeAll(suite: suite_)
4242
}
4343

44+
@MainActor
4445
@Test
4546
func testSwiftUIObserve() {
4647
let view = ContentView()

0 commit comments

Comments
 (0)