Consider the following code:
@MainActor class A {
nonisolated func foo() {
}
}
class B: A {
override nonisolated func foo() {
}
}
Why does the compiler allow me to remove the nonisolated
keyword in the subclass? The code still compiles, without errors or warnings, even when using the Swift 6 language version.
This is causing me great confusion as the AppKit NSDocument
class is marked @MainActor
, so I thought that all overridden methods that don't specify nonisolated
must also run on the main actor, but then
override func read(from url: URL, ofType typeName: String) throws {
Swift.print(Thread.isMainThread)
}
prints false
.