Xcode 16 beta 6 - unexpected concurrency build issues

The following behavior seems like a bug in the swift compiler that ships with Xcode 16 beta 6.

Add the following code snippet to a new iOS app project using Xcode 16 beta 6 and observe the error an warning called out in the comments within the itemProvider() method:

import WebKit

extension WKWebView {
    func allowInspectionForDebugBuilds() {
        // commenting out the following line makes it so that the completion closure argument of the trailing closure
        // passed to NSItemProvider.registerDataRepresentation(forTypeIdentifier:visibility:loadHandler:) is no longer
        // isolated to the main actor, thus resolving the build issues. It is unexpected that the presence or absence of
        // the following line would have this kind of impact.
        isInspectable = true
    }
}

class Foo {
    func itemProvider() -> NSItemProvider? {
        let itemProvider = NSItemProvider()
        itemProvider.registerDataRepresentation(forTypeIdentifier: "", visibility: .all) { completion in
            Task.detached {
                guard let url = URL(string: "") else {
                    completion(nil, NSError()) // error: Expression is 'async' but is not marked with 'await'
                    return
                }
                let task = URLSession.shared.dataTask(with: url) { data, _, error in
                    completion(data, error) // warning: Call to main actor-isolated parameter 'completion' in a synchronous nonisolated context; this is an error in the Swift 6 language mode
                }
                task.resume()
            }
            return Progress()
        }
        return itemProvider
    }
}

Now, comment out the line isInspectable = true and observe that the error and warning disappear.

Also filed as FB14783405 and https://github.com/swiftlang/swift/issues/76171

Hoping to see this fixed before Xcode 16 stable.

Answered by DTS Engineer in 802510022

That is some very weird behaviour you’ve got going on there. I can’t see it being anything other than a bug in the compiler itself.

Also filed as FB14783405 and

Thanks.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

That is some very weird behaviour you’ve got going on there. I can’t see it being anything other than a bug in the compiler itself.

Also filed as FB14783405 and

Thanks.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@DTS Engineer this issue is still present in Xcode 16 RC (Version 16.0 (16A242)). (I just noticed that the RC appears to have the same swift version, so this makes sense)

Yep. That matches my reading of your bug (FB14783405) and also the Swift issue that you filed.

In my testing I can work around the problem by putting the WKWebView extension into a separate file. Does that work in your setup as well? If so, that seems like a reasonable workaround for the moment.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@DTS Engineer that works but only when I have SWIFT_COMPILATION_MODE = singlefile

If I use SWIFT_COMPILATION_MODE = wholemodule, then the issue still occurs.

Perhaps this suggests a further workaround of moving the offending code into a separate module…

Yeah, I was worried that it might not be that easy )-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Sharing a further cross-post: https://forums.swift.org/t/seeking-workaround-for-issue-76171/74518

I've realized that in our full project, there is other code beyond WKWebView.isInspectable that must also be causing this issue, but I don't know of any good ways to identify all of them.

I did find one other piece of code that causes the problem by tearing the project down bit by bit until the error went away — a usage of URL(fileURLWithPath:) within an extension method on WKWebView. Other than being in an extension of WKWebView, it's not clear how this relates to the cause identified in the original post.

Suspecting something related to extensions of classes from WebKit, I tried refactoring all such extensions into helper classes, but this did not help.

Yeah, this is quite a mystery. Honestly, I think your thread on Swift Forums is the right path forward here. The folks there know a lot more about the foibles of the Swift compiler than I do!

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

We found a workaround — use Task instead of Task.detached. This happens to work regardless of whether the compiler see the NSItemProvider closures as main-actor isolated.

Xcode 16 beta 6 - unexpected concurrency build issues
 
 
Q