Undocumented changes in WebKit API in Xcode 16 break apps

Be warned! When developing your app in Xcode 16 be careful!!! The new SDK has changes that cause builds on Xcode Cloud and other non-beta Xcode to have bugs (EVEN WITH IOS TARGET SET LOWER).

This wasted 2 days of development time, but in WKNavigationDelegate, the webView(_:decidePolicyFor:decisionHandler:) method has a new type signature that will ONLY work in the latest SDK. The change was that the decisionHandler now has a @MainActor attribute. This causes Swift to recognize that it "almost" meets an optional requirement and suggests that you change it. If you change it, it will cause builds to not include the optional method.

Answered by bjosh in 797571022

Add this code:

public class Coordinator<LoginContext: CordinatedLoginContext>: NSObject, WKNavigationDelegate {
    #if compiler(>=6)
        public func webView(
            _ webView: WKWebView,
            decidePolicyFor navigationAction: WKNavigationAction,
            decisionHandler: @MainActor @escaping (WKNavigationActionPolicy) -> Void
        ) {
            // Code...
        }
    #else
        public func webView(
            _ webView: WKWebView,
            decidePolicyFor navigationAction: WKNavigationAction,
            decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
        ) {
            // Code...
        }
    #endif
}
Accepted Answer

Add this code:

public class Coordinator<LoginContext: CordinatedLoginContext>: NSObject, WKNavigationDelegate {
    #if compiler(>=6)
        public func webView(
            _ webView: WKWebView,
            decidePolicyFor navigationAction: WKNavigationAction,
            decisionHandler: @MainActor @escaping (WKNavigationActionPolicy) -> Void
        ) {
            // Code...
        }
    #else
        public func webView(
            _ webView: WKWebView,
            decidePolicyFor navigationAction: WKNavigationAction,
            decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
        ) {
            // Code...
        }
    #endif
}

Whoops, I forgot to remove the type argument. You can remove <LoginContext: CordinatedLoginContext>

@Moderators, can you edit my answer?

Undocumented changes in WebKit API in Xcode 16 break apps
 
 
Q