In new Xcode UIViewController and other UIView classes are marked as @MainActor by default:
@MainActor class UIViewController : UIResponder
But it seems no to be the same as marking UIViewController as @MainActror explicitly in code.
This code compiles:
class VC: UIViewController {
var array: [Int] = []
}
class Test {
let vc = VC()
func doSomething() {
vc.array.append(1)
}
}
but after adding "@MainActor" to VC:
@MainActor class VC: UIViewController {
var array: [Int] = []
}
class Test {
let vc = VC()
func doSomething() {
vc.array.append(1)
}
}
I got an error:
Property 'array' isolated to global actor 'MainActor' can not be mutated from this context
2
0
3.6k