3
votes

I have a dynamic framework MyFramwork.framework that has Swift code and ObjC headers marked as Protected (to be used internally in MyFramwork.framework) and Public (to be used externally by the App) in the framework's project. Also MyFramwork.framework is an embedded framework in App

Following the steps mentioned here http://nsomar.com/project-and-private-headers-in-a-swift-and-objective-c-framework/, i've created a

module MyFramwork_Private {
    header "../...h"
    ...

    export *
}

with all protected headers (SWIFT_INCLUDE_PATHS = path to directory where the module.modulemap file is)

and an PublicHeaders.h(which i import in my umbrella header MyFramwork.h) with all the public headers

How can I make a Public Swift class/struct that makes use of MyFramwork private code available in App?

If i import MyFramwork_Private in a swift file from MyFramwork, the App, when building the MyFramwork.framework, will try to access the private headers defined in module MyFramwork_Private and build fails because App can not see the protected header

1

1 Answers

5
votes

I've been struggling with this as well, this is what I found out that did the trick for me:

  1. Besides from the steps you have already taken, make sure that you create another modulemap (ex. MyFramework.private.modulemap) in $(SRCROOT)/Myframework and add the following to this file:

    module MyFramework_Private { export *
    }

  2. Edit the following options in your .xcconfig file: SWIFT_INCLUDE_PATHS = $(SRCROOT)/MyFramework MODULEMAP_PRIVATE_FILE = $(SRCROOT)/MyFramework/MyFramework.private.modulemap

After this you should be good to go, the app that is using your framework should now have a clear understanding what MyFramework_Private is and your internal Swift files have a way to access the private headers. Let me know how it worked out for you, happy to help if I can.