1

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.

Screenshot

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).

Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124

3 Answers3

3

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.
Alvin George
  • 14,148
  • 92
  • 64
  • Sorry I wasn't clear. The bridging header has been integrated. I mean, I have set the path of Objective-C Bridging Header. That's why the bridging-header.h file produces error, because it's included in the compilation. The problem is, with the current setup of importing Facebook SDK obj C headers and bridging header, I can't formulate a correct path to import the Facebook SDK. I've given the screenshot of the Facebook Core Kit SDK and the contents of the header inside, by which I tried to call `#import "FBSDKCoreKit/FBSDKCoreKit.h"` or `#import ` doesn't work. – Chen Li Yong Apr 20 '16 at 01:31
  • I also have tried `#import "FBSDKCoreKit.h"`, `#import `, `#import "FBSDKCoreKit.framework/FBSDKCoreKit.h"`, `#import `, none of them works. – Chen Li Yong Apr 20 '16 at 01:33
  • @ Chen : 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. – Alvin George Apr 20 '16 at 05:23
  • No worries, I've finally found the issue. I need to add search path for the framework because it doesn't reside inside the same folder. But thank you for answering, it gave me some insight! :) – Chen Li Yong Apr 22 '16 at 02:30
1

New File -> iOS Source -> Objective-C File -> Enter whatever (Example "abc") name -> Next, Create -> Will show message on the top, choose Create Bridging Header -> Delete abc.h -> Click ProjectName-Bridging-Header.h -> import -> finish.

Twitter khuong291
  • 11,328
  • 15
  • 80
  • 116
1

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.

Community
  • 1
  • 1
Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124