The crash below is 100% reproducible for me. My assumption was that with Strict Concurrency Checking
set to Complete
this shouldn't compile because Repository
isn't Sendable
. Is this a known bug?
Code
import SwiftUI
@main
struct AsyncAwaitWithoutActorApp: App {
@ObservedObject
var viewModel = ViewModel()
var body: some Scene {
WindowGroup {
Button("Start") {
Task {
await viewModel.run()
}
}
}
}
}
class Repository {
var results: [Int] = []
func add(value: Int) {
results.append(value)
}
}
@MainActor
class ViewModel: ObservableObject {
var repository = Repository()
func run() async {
for value in 0..<1000 {
Task {
await Operation(repository: self.repository).execute(value: value)
}
}
}
}
struct Operation {
let repository: Repository
func execute(value: Int) async {
repository.add(value: value)
}
}