Avatar
@swift-5.6.3 import Foundation struct Test { var id: Int var text: String } class Model { @MainActor var list: [Test] = [ Test(id: 1, text: ""), Test(id: 2, text: "") ] init() { Task { let updatedList = [ Test(id: 1, text: "Text1"), Test(id: 2, text: "Text2") ] for updated in updatedList { if let i = await self.list.firstIndex(where: { $0.id == updated.id }) { await MainActor.run(body: { self.updateText(i: i, value: updated.text) }) } } } } @MainActor private func updateText(i: Int, value: String) { self.list[i].text = value } }