IOS / OSX Frameworks using Swift and Objective C

Borama Apps
May 3 · 1 min read

To include Objective C code in Swift application you use bridging-header. But it’s not available inside Framework.

The solution is to make your objc header public and expose it via framework’s public header.

Create OSX project, call it Frameworks. Next create CocoaFramework (File/New/Target…) and select Swift as a language.

Inside TestFramework create swift and objective classes:

TestFrameworkObjc.h this needs to be set as public

We need to expose TestFrameworkObjc using TestFramework.h and to do that we need to change TestFrameworkObjc.h to public (in Target Membership)

set TestFrameworkObjc.h as Public

After setting TestFrameworkObjc.h to public we can update framework’s umbrella public header by adding this objc header:

Import framework in our app’s view controller and test swift class using objective class:

That’s it!

Full code here:

Please check my IOS and Android apps!

Follow me on twitter :)

Borama Apps

Written by

ios, android, web apps.,

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade