Skip to content

Commit

Permalink
Add more @mainactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Itaybre committed Jan 29, 2025
1 parent c90f85c commit 97d14ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions Examples/DemoApp/DemoApp/TestViews/PreviewVariants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extension View {

struct PreviewVariants: View {

@MainActor
init(
modifiers: [NamedViewModifier] = .previewDefault,
layout: PreviewLayout = .device,
Expand Down
10 changes: 7 additions & 3 deletions Sources/SnapshottingSwift/Initializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ public final class Initializer: NSObject, Sendable {
super.init()

#if !canImport(UIKit) || os(watchOS)
snapshots = Snapshots()
Task { @MainActor [weak self] in
guard let self else { return }
self.snapshots = Snapshots()
}
#else
NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: .main) { [weak self] notification in
Task { @MainActor in
self?.snapshots = Snapshots()
Task { @MainActor [weak self] in
guard let self else { return }
self.snapshots = Snapshots()
}
}
#endif
Expand Down

0 comments on commit 97d14ad

Please sign in to comment.