'shared' is unavailable in application extensions for iOS: Xcode 13 beta 3

Using UIApplication.shared in Swift Package produce compile time error: 'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead. Error shows after update to Xcode 13 beta 3.

Same issue here. Did you find a solution or workaround for it?

Found this thread: https://twitter.com/twannl/status/1415643862761152513

Seems like the packages needs to be updated to mark functions unavailable for extensions.

From the Xcode 13 beta 3 release notes:

Linking Swift packages from application extension targets or watchOS applications no longer emits unresolvable warnings about linking to libraries not safe for use in application extensions. This means that code referencing APIs annotated as unavailable for use in app extensions must now themselves be annotated as unavailable for use in application extensions, in order to allow that code to be used in both apps and app extensions. (66928265)

You can add the:

@available(iOSApplicationExtension, unavailable)

attribute to declarations using app extension unavailable APIs in order to get them to compile in a way that works for both apps and app extensions.

'shared' is unavailable in application extensions for iOS: Xcode 13 beta 3
 
 
Q