简体   繁体   中英

How to import obj c framework into swift bridging header?

I always find problem when importing framework headers into my project. For example, my little trial project on this screenshot. What did I do wrong when importing Facebook SDK headers? This is a very simple step and yet I can't find out what's wrong with it. I even follow the step by step closely like on the Facebook Developers site.

截图

EDIT: sorry, maybe I wasn't clear. The bridging header has been set and I've set the bridging header location path on the build settings. That's why it produces error, because it's included in the compilation. The problem is that with the current setup of importing Facebook SDK and bridging header, I can't import the Facebook SDK into the bridging header.

Things I've tried:

  • #import "FBSDKCoreKit/FBSDKCoreKit.h"
  • #import <FBSDKCoreKit/FBSDKCoreKit.h>
  • #import "FBSDKCoreKit.h"
  • #import <FBSDKCoreKit.h>
  • #import "FBSDKCoreKit.framework/FBSDKCoreKit.h"
  • #import <FBSDKCoreKit.framework/FBSDKCoreKit.h>

None of them works (all of them produces error like on the screenshot, means that the bridging-header is fine and included in the compilation, but it can't find the header I refer to).

Make a Obj C Bridging:File -> New -> Source -> Header File -> Name as AppName-Bridging-Header.

Add the following (ex. in case of SDWebImage):

  #ifndef AppName_AppName_Bridging_Header_h
        #define AppName_AppName_Bridging_Header_h

        #import <SDWebImage/UIImageView+WebCache.h>
        #import "UIImageView+WebCache.h"
        #endif

    or

 #import "UIImageView+WebCache.h"  

Note: Build Settings, in Swift Compiler - Code Generation, make sure the Objective-C Bridging Header build setting under has a path to the bridging header file. - its like testSD/testSD-Bridging-Header.h or testSD-Bridging-Header.h (Open the Project folder and find the header file path)

@Chen : In your case, try Adding the “-ObjC” Linker Flag.

Select the project file from the project navigator on the far left side of the window.

Select the target for where you want to add the linker flag.

Select the “Build Settings” tab.Choose “All” to show all Build Settings.

Scroll down to the “Linking” section, and double-click to the right of where it says “Other Linking Flags”.

A box will appear, Click on the “+” button to add a new linker flag.
Type “-ObjC” (no quotes) and press enter.

新建文件-> iOS源-> Objective-C文件->输入任何名称(例如“ abc”)名称->接下来,创建->将在顶部显示消息,选择创建桥接标题->删除abc.h->单击ProjectName-Bridging-Header.h->导入->完成。

Now I've found the answer. The problem is that the framework doesn't stored inside the project folder but in download folder. And yeah, Facebook dev guide told me to drag the framework straight from where the framework is downloaded, and I didn't check the 'copy files if needed' checkbox when importing. From this answer , I found out that I need to fill in search path to the framework base folder in order for Xcode to be able to find it. Thanks for everyone for answering.

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