Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Objective-c framework into Swift framework project

I am building a framework in which I need to import some objective-c frameworks for now I need to import "Beaconstac.framework" but as we can not add a bridging header in a swift framework project so my question is how can I use this framework in my project this is not directly accessible in my project I tried

import Beaconstac

but its giving error "No Such Module"

is there any alternative to do this?

like image 938
Krishna Verma Avatar asked Nov 19 '15 07:11

Krishna Verma


People also ask

Is Swift interoperable with Objective-C?

Swift has its own runtime, but it also has access to Objective-C runtime, and also access to C . Having access to those runtimes makes the interoperability between Swift and Objective-C easier to bridge.

Can you call Swift from Objective-C?

Call Swift from Objective-CThe Swift library cannot be directly called from Objective-C, since it is missing the required annotations in the code, and in many cases, modules do not inherit from NSObject, rather they use the native Swift data types.


1 Answers

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

like image 68
Atul Avatar answered Nov 15 '22 21:11

Atul