So many frameworks in macOS SDK still don’t seem to be annotated for Swift 6, even a year later. I'll use one example to elicit advice: let’s look at CAMetalLayer
.
Like most NSObject
subclasses in the SDK, it is not Sendable
. As a CALayer
subclass it is useful in a UI context, but because it is a performance-sensitive bridge to Metal, one of its methods is callable from any thread: nextDrawable()
.
If I understand where things should be, that method will eventually be annotated with NS_SWIFT_NONISOLATED
. But since it isn't, the only way to stop the Swift 6 compiler from complaining and/or avoiding a runtime crash due to an isolation-related exception, is to lie and make the entire class Sendable
:
extension CAMetalLayer : @retroactive @unchecked Sendable { }
Now we’ve made a false promise about all other methods and properties in the class. Is there any way to improve on this? For example, something like this:
extension CAMetalLayer {
@retroactive nonisolated func nextDrawable() -> (any MTLDrawable)?
}
My guess is no, but I hope to be wrong about this.