1

I'm building this Swift static library: OxfordLibrary that I ultimately want to distribute using XCFramework.

I have some ObjC/C++ code that want to access from Swift. Since We can't use ObjC bridging header in Static libraries (Throws errors when creating XCFramework), So I'm trying to use modulemap files.

So idea was keeping ObjC/C++ code base internal / private to library and only expose APIs via Swift.

So I created following:

/// FILE: module.modulemap

module OxfordLibrary {
    export *
}
/// FILE: module.private.modulemap

module OxfordLibrary_Private {
    umbrella header "OxfordLibrary-objc-umbrella.h"
    export *
}

I have set the Defines Module: YES and also set the swift Seach Path in build settings.

Now in my Main Swift file:

/// FILE: OxfordLibrary.swift

#import OxfordLibrary_Private

open OxfordLibrary{
    public static func foo() {
        SomeObjcClass.someObjcMehtod()    // Final aim
    }
}

Now without importing OxfordLibrary_Private I can't access SomeObjcClass in swift. Fine. After adding import it works.

This even builds correctly.

But when I create XCFramework from this and import that XCFramework to client app project, and I do import OxfordLibrary then it throws error OxfordLibrary_Private module not found / not defined.

After doing some research I found I need to copy modulemap files and headers to XCFramwork either in Modules folder or using -headers flag. It works if I do that.

But question is: Its private.modulemap supposed to be private and not avaible outside of the library?

Because now I can do import OxfordLibrary_Private in client app and access any ObjC method there.

ImShrey
  • 380
  • 4
  • 12
  • dont understand the question you made it `public static`.. so to me it looks fine. is'nt the modulemap exactly meant to be able to know the symbols for in example debugging. – Ol Sen Jan 07 '22 at 20:07
  • Just use SPM. It will create valid modulemaps for you. – Cy-4AH Jan 07 '22 at 21:44
  • @OI Sen yeah right, but in my client App I'm able to import and use all ObjC classes which I don't want. I have requirement where objective C class will be private. And Swift layer on top of them is only publicly available. – ImShrey Jan 09 '22 at 04:09
  • Actually @Cy-4AH I'm already using Tuist for this and that's enough. Because this library will be a part of a cross platform C++ library. – ImShrey Jan 09 '22 at 04:11
  • SPM is crossplatform – Cy-4AH Jan 09 '22 at 09:17

0 Answers0