I've encountered an issue after upgrading to Xcode 16. I have an overridden func of WebKit.WKWebView.evaluateJavaScript(_:completionHandler:), which no longer compiles in the new Xcode. I noticed that in Xcode 16, the completionHandler now has @MainActor and @Sendable annotations, which causes a compilation error.
public override func evaluateJavaScript(_ javaScriptString: String, completionHandler: (@MainActor @Sendable (Any?, (any Error)?) -> Void)? = nil)
When I add these annotations to my overridden method, it compiles fine in Xcode 16. However, this breaks compilation in older versions of Xcode. The documentation for this API doesn't explicitly mention any changes, but the behavior is clearly different between versions.
https://developer.apple.com/documentation/webkit/wkwebview/1415017-evaluatejavascript
Xcode 15:
Xcode 16:
What would be the best way to handle this situation? Should I use a compilation condition to differentiate between the versions? If so, what would be the correct condition to check? Was there a Swift compiler update in Xcode 16 that could be affecting this?
Or is it better to drop support for versions of Xcode earlier than 16?
Or I should not override that?
Thanks in advance for any insights!