Is there a way to specify APPLICATION_EXTENSION_API_ONLY on a SPM package? I've tried the following but I don't get any warnings when compiling when a missing API is used.

    swiftSettings: [

For context, here's a link to the App Extension Programming Guide

This setting should already be true in most cases, see

Did you see any issues with that?

I have not seen that. It is very helpful.

I am not sure if it helps though. If I understand correctly the APPLICATION_EXTENSION_API_ONLY=YES is automatically added if there are no system modules linked to the SPM package. Assuming that UIKit is a system module, this would mean that for a SPM package that uses UIKit the APPLICATION_EXTENSION_API_ONLY would not be set. So for example if I had common UI code within a SPM package that imported UIKit used both by an iOS app and an extension, no warnings are triggered.

This refers to using packages which use things like, for libraries that are part of the SDK, you explicitly do not have to use this API.

for libraries that are part of the SDK, you explicitly do not have to use this API.

I'm not sure I understand what you mean by that. Would you mind clarifying it for me?

If a package is using a library that's part of the SDK, such as UIKit, it won't use the systemLibrary(name:path:pkgConfig:providers:) API at all and therefore would not end up being a package that depends on a system module for the purpose of the check in

If UIKit is not considered system module under this scenario, then I understand that APPLICATION_EXTENSION_API_ONLY=YES is being set when my package is built.

However, using an API that is not available does not give any warnings/errors. For example, I can write in an SPM package:

public func someFunction() {
    let app = UIApplication.shared

And I can import that package from the extension and call this function. There is no runtime crash and the extension runs normally, even printing the application but I'd like to think that there is a reason this is marked as NS_EXTENSION_UNAVAILABLE.

If I write that function in the extension target it triggers a build error preventing me from building that extension altogether. This is what I would expect when defining such a function in a SPM package. Am I misunderstanding something?

This is indeed a bug and should produce a build error as you mentioned - can you please also file an issue using Feedback Assistant which we can use to track this?

Thank you for the quick responses. I've submitted a bug with a link to this thread,

Terms of Service

Privacy Policy

Cookie Policy