The problem is that someone can mutate a1 before, and during the tasks runtime. One way to fix this is to make ContentView run all its accesses on the main thread by making it a @MainActor like so:
@MainActor
struct ContentView: View {
If having all interactions run on the main thread is not ideal you could also make ContentView an actor like so:
actor ContentView: View {
...
nonisolated var body: some View {
The nonisolated tells the compiler to not implicitly make it isolated, which would make that function no longer able to comply with the protocol View. For a Swift View id recommend going the @MainActor annotation.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: