Cannot use a local XCFramework in Swift (works in Obj-C)

Hello,

I've been trying for a few days to import a local XCFramework into my Swift code, with no success.

Xcode keeps erroring with: "No such module". I've made a minimal reproducible example on GitHub.

Interestingly, it does work with an Obj-C project with no issue.

Both projects were created with pod lib create. I've tried adding a random module.modulemap to my XCFramework, no success.

After browsing forums / documentation for a few days, I yield and post here.

Hope someone can help 🙏

Answered by TheoDelrieu in 719957022

I found a workaround.

It seems that XCFramework are not Frameworks, thus they cannot be modularized. So I did copy the C "umbrella" header to my source tree, and defined an explicit module in a custom module.modulemap (adding a custom umbrella header too).

I can successfully import this submodule in my swift code, and call C stuff.

Here's the modulemap code:

framework module Add {
  umbrella header "Add-umbrella.h"

  export *
  module * { export * }

  explicit module Core {
    private header "add.h"
    export *
  }
}
Accepted Answer

I found a workaround.

It seems that XCFramework are not Frameworks, thus they cannot be modularized. So I did copy the C "umbrella" header to my source tree, and defined an explicit module in a custom module.modulemap (adding a custom umbrella header too).

I can successfully import this submodule in my swift code, and call C stuff.

Here's the modulemap code:

framework module Add {
  umbrella header "Add-umbrella.h"

  export *
  module * { export * }

  explicit module Core {
    private header "add.h"
    export *
  }
}
Cannot use a local XCFramework in Swift (works in Obj-C)
 
 
Q