9

Setup

  1. I create a swift framework which include C library (CommonCrypto) and a Objective C file.

  2. There is no bridge-header in swift project. So I create a module.modulemap to import CommonCrypto and Objective-C file into my swift framework.

    module.modulemap content: enter image description here

Here is the module.modulemap sample link:Importing CommonCrypto in a swift framework

  1. In project settings, adding modulus.modulusmap path to swift compileenter image description here

    So, in my swift framework, everything works fine. I can use modulus like this

    enter image description here

Problem shows

  1. Archive the modular framework and export as a built products.

  2. In my swift sample project, add modular framework to Embedded Binaries enter image description here

  3. Error occurs on this line when I use something inside the framework enter image description here

I have try so many solutions, but still not work.

Similar problems:

  1. Swift app: “Missing required module” when importing framework that imports static library

  2. Adding RealmSwift as a subproject: Missing required modules: 'Realm.Private', 'Realm'

Is anyone have a good solution for this? Thx!!

HungCLo
  • 442
  • 2
  • 6
  • 21
  • Do you plan to distribute this framework to others? Or would it be suitable to just keep it in the same Xcode workspace as the project(s) you want to use it in? – Matthew Seaman Feb 07 '17 at 08:53
  • 2
    It's a commercial framework. I would distribute this to others and many other unrelated projects. If I use the framework in my own project on my development environment, works fine. But, for the projects on someone's development environment shows the problem. – HungCLo Feb 07 '17 at 08:58
  • See if this helps: http://stackoverflow.com/questions/37108539/importing-pure-swift-custom-framework-into-other-swift-project?rq=1 – Matthew Seaman Feb 07 '17 at 19:16
  • Thanks man. Finally, I got a solution. It's a bit wired but work fine. I will post it later. – HungCLo Feb 08 '17 at 09:26
  • @HungCLo I had same problem too. Could you help me, please? – yycking Apr 05 '17 at 07:06
  • Ok. I found a workaround. Redefine module.modulemap on sample project. ex: module CommonCrypto { } – yycking Apr 05 '17 at 08:33
  • @yycking Thanks. I already found out a solution. If you are still interesting about the question, you can see the solution. – HungCLo Apr 05 '17 at 10:11
  • Hi, @HungCLo i have the same problem can you share your solution with me pls? – SOUA Hamza Jun 27 '17 at 15:11
  • Hi, @SOUAHamza, I post an answer as you wish. Hope it helpful. – HungCLo Jun 28 '17 at 03:33
  • Will it be able to hide Objective-C files from the user of this framework? – nr5 Jun 25 '19 at 11:12

1 Answers1

7

Solution

iOS framework exists as a folder, create a module.modulemap to find out library or header file.

  1. Setup module.modulemap path

    In project/target/Build Settings/Swift Compile - Search Path/Import Path = “${SRCROOT}”

  2. Add below to module.modulemap

enter image description here

Remarks

You don't have to add module.modulemap to the sample project if the framework is archived on the same development environment.

HungCLo
  • 442
  • 2
  • 6
  • 21
  • Thank you @HungClo , so if i understand i have to add the module map in the project that is using my Framework ? , and i need to run it on other environment – SOUA Hamza Jun 28 '17 at 10:42
  • Exactly, module map helps you find out your framework. It's the same on other environment. – HungCLo Jun 29 '17 at 01:20
  • Thank you, but i need to add the framework to a project outside of the environment without module map , but it seem like impossible for now in SWIFT – SOUA Hamza Jun 29 '17 at 07:37
  • You can find out if the framework share the header files or not in the framework folder. Assume that you can access header files, you also can try the solution. Let me know if it works!~ – HungCLo Jun 29 '17 at 09:21
  • I try to reproduce this project but without success. https://github.com/danieleggert/mixed-swift-objc-framework – SOUA Hamza Jul 13 '17 at 11:21
  • it probably works for you, but take into the account, that the base of your trouble is how you defined module.modulemap. I suggest you check Clang documentation https://clang.llvm.org/docs/Modules.html#module-map-language (see framework keyword). without "framework module', your module.modulemap is not available externally. – user3441734 Jul 30 '17 at 19:06
  • @SOUAHamza declare your module as 'framework module' and the module.modulemap will be part of your framework. – user3441734 Jul 30 '17 at 19:09
  • not work for me, since my OC header is not public, it is not visible outside of the framrwork. – DàChún Oct 10 '17 at 19:08
  • @User9527 since you say it is not visible to the end user. If I keep my OC header as private or project in target membership. I get this error: nclude of non-modular header inside framework module '... Any help! – nr5 Jun 25 '19 at 11:14