diff --git a/Sources/TaskTrigger/View+Task.swift b/Sources/TaskTrigger/View+Task.swift index e44f725..60d6fa7 100644 --- a/Sources/TaskTrigger/View+Task.swift +++ b/Sources/TaskTrigger/View+Task.swift @@ -26,7 +26,7 @@ public extension View { /// - action: An async action to perform whenever the trigger fires. func task( _ trigger: Binding, - _ action: @escaping @Sendable () async -> Void + _ action: @escaping @Sendable @MainActor () async -> Void ) -> some View { modifier(TaskTriggerViewModifier(trigger: trigger, action: { _ in await action() })) } diff --git a/TaskTriggerDemo/TaskTriggerDemo/ContentView.swift b/TaskTriggerDemo/TaskTriggerDemo/ContentView.swift index 96501dd..d8fc5c0 100644 --- a/TaskTriggerDemo/TaskTriggerDemo/ContentView.swift +++ b/TaskTriggerDemo/TaskTriggerDemo/ContentView.swift @@ -95,14 +95,12 @@ struct ContentView: View { operation like a network call or some other (possibly) expensive operation. */ - @MainActor private func setRandomNumber(_ value: Int) async { try? await Task.sleep(for: .seconds(1)) if Task.isCancelled { return } self.randomNumber = value } - @MainActor private func resetToZero() async { try? await Task.sleep(for: .seconds(1)) if Task.isCancelled { return }