Avatar
Avatar
fummicc1
@swift-5.6.3 @swift-5.7.3 import Foundation struct Test { var text: String } class Model: ObservableObject { @MainActor @Published var list: [Test] = [] init() { Task { let updatedList = [ Test(text: "Text1"), Test(text: "Text2") ] for updated in updatedList { if let i = await self.list.firstIndex(where: { $0.text == updated.text }) { await MainActor.run(body: { self.list[i].text = "Changed" }) } } } } }
exit status: 1 with stderr:<stdin>:8:17: error: unknown attribute 'Published' @MainActor @Published var list: [Test] = [] ^ <stdin>:7:14: error: cannot find type 'ObservableObject' in scope class Model: ObservableObject { ^~~~~~~~~~~~~~~~ <stdin>:19:30: error: actor-isolated property 'list' cannot be passed 'inout' to 'async' function call self.list[i].text = "Changed" ^ <stdin>:8:31: note: property declared here @MainActor @Published var list: [Test] = [] ^