I am trying to extend UIApplication to conform to a custom protocol AppSwitcher for handling URL opening. This code worked fine in Xcode 15, but after upgrading to Xcode 16, it is causing errors.
public protocol AppSwitcher {
func open(
_ url: URL,
options: [UIApplication.OpenExternalURLOptionsKey: Any],
completionHandler completion: ((Bool) -> Void)?
)
}
extension UIApplication: AppSwitcher {}
n Xcode 16, I can no longer extend UIApplication to conform to my AppSwitcher protocol without encountering errors. It worked perfectly in Xcode 15.
- Has anyone else experienced this in Xcode 16?
- Is this a change in Swift 5.9 or the iOS SDK?
- What’s the reason behind this change, and are there any workarounds to achieve the same result?
2
Answers
This is a change in the iOS SDK. The
open
method now has more annotations on its completion handler –@MainActor
and@Sendable
.You should add those to your protocol method too.
Also consider using the
async
version of theopen
method in your protocol.If this change breaks some other parts of your code, that means you were not using
open
in a concurrency-safe way in the first place.FYI if you want to compile code in Xcode15 after updating on
you can use #if compiler(>=x.x.x)
for xcode 15.1 compiler is 5.9.2
for xcode 16.1 compiler is 6.0.2