简体   繁体   中英

How to use Objective-C bridging header in a Swift project

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:

在此处输入图片说明

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.

在此处输入图片说明

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" eg 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

转到构建设置并搜索 Objective-C Bridging Header 键并提供桥接头文件的路径。在我的情况下,它是“Main/Main-Bridging-Header.h”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM