4

I created a simple iOS framework Swift project and added a single Swift class Logger with a single stub method log(_:)

class Logger: NSObject {

    func log(_ message:String) {
        // ...
    }
}

The Logger class and log method are internal to the framework, and building normally does not expose them to ObjC. If I check the "Allow app extension API only" in the General settings of my framework target, though, the generated MyFramework-Swift.h now contains both the class and method declaration, meaning that both are visible to consumers of the framework as if they were declared public:

SWIFT_CLASS("_TtC9Framework6Logger")
@interface Logger : NSObject
- (void)log:(NSString * _Nonnull)message;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

Can someone please explain why? Thanks in advance!

1
  • You shouldn't use screenshots to post code snippets.
    – Losiowaty
    Feb 19, 2017 at 0:18

2 Answers 2

5

As soon as you enable "Allow app extension API only" the generated header will contain both public and internal classes.

I believe that this is probably a bug in Xcode as this setting should only affect warnings emitted from your compilation (if you reference non-extension APIs) and not affect the contents of the generated Module-Swift.h

I am filing a bug report right now.

1
  • I came across this problem using Xcode 12.5. I also checked out your sample project from RadarSample repo and effectively the problem still occurs (the generated headers differ). The problem is that my project build fails since, when flagging "Allow app extension API only" it cannot find a module which gets imported in the wrongly generated header for Swift. Do you know any workaround for avoiding this?
    – francybiga
    Sep 10, 2021 at 13:52
0

Xcode Allow app extension API only

When you check Allow app extension API only on a framework target(now it is not presented on General tab) it force a compiler to check if the framework doesn't call any prohibited system API (Forbidden API NS_EXTENSION_UNAVAILABLE )

//warning
linking against dylib not safe for use in application extensions

All targets has this reflection in Build Settings. It is Yes by default for app extension targets

Require Only App-Extension-Safe API APPLICATION_EXTENSION_API_ONLY

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.