15

I am building a framework in which I need to import some objective-c frameworks.

For now I need to import "Beaconstac.framework", but we can not add a bridging header in a swift framework project.

How can I use this framework in my project?

I tried:

import Beaconstac

But the compiler reports error "No Such Module"

Is there any alternative way to do this?

11
  • Check this out stackoverflow.com/questions/24002369/… Commented Nov 19, 2015 at 7:04
  • And this developer.apple.com/library/ios/documentation/Swift/Conceptual/… Commented Nov 19, 2015 at 7:04
  • this answer is about how to use objective-c framework in swift but i am developing a swift framework not swift application Commented Nov 19, 2015 at 7:08
  • Doesn't matter you creating framework or application. you should be able to add external files to your project by bridging ! or may be i didn't get your concern? Commented Nov 19, 2015 at 7:17
  • 2
    we can not add a bridging header if we are creating a framework in swift. Commented Nov 19, 2015 at 7:22

3 Answers 3

18

Steps to include an existing Obj C framework in a swift framework project

Say we are creating an “SwiftProj.framework" project in swift which internally has to use an Objective C “ObjC.framework”

  1. Place the ObjC.framework in Frameworks folder, Link to Swift framework project via Linked Frameworks and Libraries, and create a module.modulemap file at the same level.
  2. In module.modulemap
module ObjC{
    header "ObjC.framework/Headers/ClassA.h"
    export *
}
  1. Create xcconfig file (File->New->iOS->Other->Configuration Settings file)

  2. In xcconfig file

SWIFT_INCLUDE_PATHS = $(SRCROOT)/
MODULEMAP_PRIVATE_FILE = $(SRCROOT)/module.modulemap

Now you can access ObjC.ClassA in SwiftProj.framework

Sign up to request clarification or add additional context in comments.

6 Comments

Do you have an example project for this?
@girish, I tried this, but not working. How did you make it to work? Could you give me some hint on anywhere that I need to be careful about? Also when you create .xcconfig file, did you set the config path anywhere? Appreciate your help.
@Atul, where to place the xcconfig file? How the project recognize the xcconfig file, too? Could you give more detail about it
@Atul followed same steps. But got error header "ObjC.framework/Headers/ClassA.h" not found.
what if we are using CocoaPods? where should the module.modulemap file be located?
|
4

Create a file called module.modulemap and include the following contents:

module ObjCFrameworkName {
    header "ObjCFrameworkName.framework/Headers/ObjCFrameworkNameUmbrellaHeader.h"
    export *
}

Be aware that you need to have the correct path to your Obj-C framework's umbrella header which may differ slightly with what's listed in the example above.

If you are still stuck, I would strongly suggest taking a look at this project.

Comments

2

You need to import the Beaconstac framework in your umbrella header. That is, if you'd ordinarily use, e.g., #import <Beaconstac/Beaconstac.h> in an Obj-C bridging header, for a framework you need to put that in the umbrella header.

See this chapter in Apple's documentation for more info:

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-ID130

3 Comments

its giving me error "include non modular header inside framework module"
@KrishnaVerma How did you fix that?
@KrishnaVerma I have the same issue. Did you find the solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.