nh7a
March 18, 2022, 1:59pm
2
Searching forums, I found @bjhomer already asked below a year ago - [Pitch] Global actors - #4 by bjhomer
I assume this means that overridden declarations from a non-isolated superclass are not actor-isolated to the global actor, which would mean that in the following code, viewDidAppear
would not be actor-isolated:
@MainActor
class IconViewController: UIViewController {
var url: URL?
override func viewDidAppear() {
// Error: cannot access actor-isolated property 'url'
// from non-isolated context
self.url = URL(string: "https://example.org")!
}
}
This seems annoying, since viewDidAppear
is always going to be called on the main thread (as per the UIKit/AppKit framework). Is there any mechanism proposed whereby ObjC code can declare a type as actor-isolated?
And @Douglas_Gregor replied.
Yes, one can use __attribute__((swift_attr("@MainActor")))
to state that an Objective-C declaration will always be called on the main actor. Of course, we can't verify that from the Objective-C side, but it makes annotation possible. This is documented in SE-0297 , albeit somewhat indirectly because we hadn't written up the global-actors pitch fully at that time.
So, it wasn't used for those UIKit methods as of Xcode 13.3... seems the case.
Since it's UIKit stuff, maybe it's not something we should discuss here but this is extremely unfortunate because the concurrency warning flag is practically unusable for its main purpose when it produces hundreds of warnings because of those override
methods