How to import Objective C static library to Swift Framework? How to import Objective C static library to Swift Framework? swift swift

How to import Objective C static library to Swift Framework?


The easiest way to accomplish that is to use a module map file. Below I assume you have the Proto.framework in a separate project, which is called Proto.

  1. Create a module.modulemap file in your framework containing the following (substitute the path to the header file as needed):

_

framework module Proto {    umbrella header "Proto.h"    // Load a C header to be used in Swift - here /usr/include/sys/stat.h:    header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys/stat.h"    export *    module * { export * }}
  1. In your project build settings find Module Map File in section Packaging. Enter $(SRCROOT)/Proto/module.modulemap

That's it. From now on you should be able to use anything declared in stat.h in Swift.


In your build settings for Proto.framework try setting the option Allow Non-modular Includes In Framework Modules to Yes.

Xcode Settings


I resolved this error by making the header Public (instead of Project)

Go to your target Build Phases and move the header accordingly:

Header visibility settings

This works for my 'lib' target. But I am still unable to build libTests target. Here I get 2 errors:

  • 'header.h' file not found with include; use "quotes" instead
  • and again: Include of non-modular header inside framework module 'lib'

this I am not able to resolve yet