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.