Swift 6 and 5 - Strict concurrency: complete and WKNavigationDelegate decidePolicyFor not being called.

decidePolicyFor delegate method:

import WebKit

@objc extension DocumentationVC
{
    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void)

Being called just alright in swift 5 minimal concurrency.

Raising concurrency to complete with swift 5 or swift 6. Changing the code to avoid warnings:

@preconcurrency import WebKit

@objc extension DocumentationVC
{
    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {

The delegate method is not being called. Changing back to swift 5 concurrency minimal - it is called.

Looking at WKNavigationDelegate:

WK_SWIFT_UI_ACTOR
@protocol WKNavigationDelegate <NSObject>


- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(WK_SWIFT_UI_ACTOR void (^)(WKNavigationActionPolicy))decisionHandler WK_SWIFT_ASYNC(3);

Changing the delegate method to:

    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping @MainActor (WKNavigationActionPolicy) -> Void) {

And it is called across swift 5 concurrency minimal to complete to swift 6.

I thought, the meaning of @preconcurrency import WebKit was to keep the delegate without @MainActor before the (WKNavigationActionPolicy) still matching regardless the swift concurrency mode?

My point is - this can introduce hidden breaking changes? I didn't see this documented anyhow at: https://www.swift.org/migration/documentation/migrationguide/.

decidePolicyFor is an optional method - so if signature 'mismatches' - there will be no warning on not-implementing the delegate method.

How do we catch or diagnose irregularities like this? Is it something @preconcurrency import WebKit should be ensuring and it is not?

Is this delegate mismatch a bug on swift side or something we should be taking care of while migrating? If it is on us, how do we diagnose these potential mismatches?

Just to clarify "Changing the code to avoid warnings:" - the only warning is exactly to update to: @preconcurrency import WebKit.

Swift 6 and 5 - Strict concurrency: complete and WKNavigationDelegate decidePolicyFor not being called.
 
 
Q