UIDevice: Main actor-isolated class property 'current' can not be referenced from a non-isolated context

I have a Safari Web Extension for visionOS that reads from UIDevice.current.systemVersion in order to provide the OS version number back to the JavaScript context utilizing beginRequest(with:).

When switching my project to use Swift 6, I received this obscure error:

Main actor-isolated class property 'current' can not be referenced from a non-isolated context

Class property declared here (UIKit.UIDevice)

Add '@MainActor' to make instance method 'beginRequest(with:)' part of global actor 'MainActor'

Adding @MainActor causes another issue (Main actor-isolated instance method 'beginRequest(with:)' cannot be used to satisfy nonisolated protocol requirement) which suggests adding @preconcurrency to NSExtensionRequestHandling which then breaks at Non-sendable type 'NSExtensionContext' in parameter of the protocol requirement satisfied by main actor-isolated instance method 'beginRequest(with:)' cannot cross actor boundary.

What's the proper solution here?

Here's a simplified snippet of my code:

class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
  func beginRequest(with context: NSExtensionContext) {
    // ...

    var systemVersionNumber = ""
    systemVersionNumber = UIDevice.current.systemVersion

    // ...
  }
}

Since UIDevice is only supported on the main thread, we would likely recommend you use NSProcessInfo instead, or cache this value once early on before it is needed.

UIDevice: Main actor-isolated class property 'current' can not be referenced from a non-isolated context
 
 
Q