OK, all of a sudden I’m getting warnings (and runtime errors) in code that hasn’t changed in quite some time. I believe this has to do with Swift concurrency.
Further details below. All help appreciated greatly. On where to look next.
Using the example code from Apple also shows this issue.
I’m getting errors using the new environment variables to open an existing document: Apple Developer Link
I get this error when I have my swiftui View as being @MainActor:
2
Answers
Thank you @Lorem Ipsum and @malhal for trying to help and not just down voting.
For others having similar issues the answer was to do as Lorem ipsum suggested to make the parent view @MainActor, but also to pull the code out of the view body and into it's own method and call that async method from a Task call within the view body.
In my code I am declaring the Environment variable within the view as before but have moved the call to it to a function inside the View:
It’s
.task
in SwiftUI notTask
. In your case probably something like: