[Regression][Xcode 13.0b3]: a normal target in a linked SwiftPM library is treated as an app extension

Feedback ID: FB9337463

Hello,

When compiling our application, I see the following problem reproduced with the attached sample example (modified the following repository sample as the problem happens in this library: https://github.com/ephread/Instructions.git ):

$HOME/Library/Developer/Xcode/DerivedData/Instructions_Example-hhbleavuawdnqpbogvbuddnqmepj/SourcePackages/checkouts/Instructions/Sources/Instructions/Core/Public/CoachMarksController.swift:215:48: error: 'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead.
            if let windowScene = UIApplication.shared.activeScene {

Note that this was not happening in our app or this sample project with Xcode 13.0 beta 2, it started happening today when I updated to Xcode 13.0 beta 3).

Thank you in advance for your help :)!

Kind Regards,

Goffredo Marocchi

Sample projects (archive): https://www.icloud.com/iclouddrive/0rc9JcVxDKFF6I8hfzZ7_6KLQ#SampleIssue%5FProj

Kind Regards,

Goffredo

Answered by Goff.Marocchi in 686833022

The change has been reverted in SwiftPM (Xcode 13 beta 5 for sure) so now this problem should not affect apps and libraries anymore (although some libraries like Firebase had already adapted successfully to it)

Also experiencing this issue, no extensions in our app and the error is in a couple of dependencies. Anyone have a workaround that doesn't involve forking the dependencies?

I think it is a SwiftPM change. Integrating the library through CocoaPods solves the problem here and passes it down to the next library integrated through SwiftPM.

Also experiencing this. Earlier today I also filed a radar ID FB9334019 with a sample project (nothing complex, all that’s needed is to make a new project in Xcode and add a Swift Package dependency that references UIApplication.shared). Would love to know if there’s a workaround (aside from using Cocoapods I guess :))

Apparently this is by design: https://forums.swift.org/t/set-application-extension-api-only-on-a-spm-package/39333/11

This breaks also other libraries like Firebase App Diatribution used in an app without any app extension target. It would be nice as the app developer to be able to tell SwiftPM there is no App Extension target :/.

Will try to raise this issue in all the projects I can see are affected :(… might take a while. Will add links here if it is allowed.

@Goff.Marocchi Your link helped a lot, thanks! If I go into the SPM cache, unlock the files, and add @available(iOSApplicationExtension, unavailable) to all the classes of the cached Swift Package that's failing, then the error goes away. So at least this is a workaround.

Obviously if I was using the package in an extension I'd need to annotate specific methods and so on with the same code, but in my case the class-level hack did the trick, as I only used the package in the main app target.

I'll do the same as you and raise an issue for Swift Packages in my project that needed this hack in the hope we can spare others this headache.

I also faced such a problem for the SwiftMessages library, which is simply present in the local SPM framework. Appeared only on XCode 13 beta 3, before that on XCode 12 everything works fine.

The change has been reverted in SwiftPM so now this problem should not affect apps and libraries anymore (although some libraries like Firebase had already adapted successfully to it).

Accepted Answer

The change has been reverted in SwiftPM (Xcode 13 beta 5 for sure) so now this problem should not affect apps and libraries anymore (although some libraries like Firebase had already adapted successfully to it)

[Regression][Xcode 13.0b3]: a normal target in a linked SwiftPM library is treated as an app extension
 
 
Q