Hello Folks,
I have this code here. I'm getting the error, see screenshot.
Assumptions:
- Is the code on
line 11running on the MainActor and Not the FactoryActor? even through the closure is invoked online 22in the factory actor - Can't modify the
NoneSendableWorkUnit, b/c it's a SwiftData @Model
Question:
- is there a way to run line 11 in the factory actor isolation context?
Screenshot:
Code:
1. import SwiftUI
2. @main
3. struct MyApp: App {
4. let factory = Factory()
5.
6. var body: some Scene {
7. WindowGroup {
8. Text("hello")
9. .task {
10. await factory.enqueue { unit in
11. unit.work += 1
12. }
13. }
14. }
15. }
16. }
17. class NoneSendableWorkUnit {
18. var work: Int = 0
19. }
20. actor Factory {
21. func enqueue(work: (NoneSendableWorkUnit) -> Void) async {
22. work(NoneSendableWorkUnit())
23. }
24. }
