4

I've been asked to use a Objective-C framework in my Swift project.

But I have no idea how to accomplish this.

I've added this file:

Objective-CBridgingHeader.h

Inside this file I've put:

#ifndef Objective_CBridgingHeader_h
#define Objective_CBridgingHeader_h

#import <FMShop/FMShop.h>

#endif /* Objective_CBridgingHeader_h */

Now I was expecting to be able to:

Import FMShop

And get access to that framework using Swift code. However when I try to

Import FMShop

My project no longer compiles claiming that there: "No such module 'FMShop'"

What am I missing here?

My base SDK is iOS 8.0 and I'm using Xcode 7.3.1

This is what my project looks like:

enter image description here

pkamb
  • 33,281
  • 23
  • 160
  • 191
Rutger Huijsmans
  • 2,330
  • 2
  • 30
  • 67
  • Possible duplicate of [How to call Objective-C code from Swift](http://stackoverflow.com/questions/24002369/how-to-call-objective-c-code-from-swift) – Mr. Xcoder Jan 22 '17 at 06:49

2 Answers2

5

Add a new Objective-C file to your Xcode project. Name it as you please and you should get an alert box asking if you would like to create a bridging header. Then delete that file as it was just used to create Bridging Header.

enter image description here

Alternatively you can you can create a bridging header yourself by choosing File > New > File > (iOS, watchOS, tvOS, or macOS) > Source > Header File. Name the file as "ProjectName-Bridging-Header.h" e.g. if Project Name is Test then give file name as "Test-Bridging-Header.h".

https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

Suhit Patil
  • 11,748
  • 3
  • 50
  • 60
1

Go to build settings and search for Objective-C Bridging Header key and provide path of your bridging header file.In my case it is "Main/Main-Bridging-Header.h".

Nuzhat Zari
  • 3,398
  • 2
  • 24
  • 36