问题
I am converting my application from Objective- C to swift . In my swift application I have created a header file as explained in following tutorial , but i am getting error 'FacebookSDK/FacebookSDK.h' file not found rather than I imported facebookSDK successfully in my application . Please guid me how to import facebookSDK in swift.
回答1:
Facebook supports swift natively as of SDK v4.1, so bridging headers are not required now. (by the way, they also deprecated FacebookSDK in favor of FBSDKCoreKit since this version)
Just import the module you need directly:
import FBSDKCoreKit
import FBSDKShareKit
import FBSDKLoginKit
回答2:
Here is a simple way to do it right:
- Create a Swift project
- File > New > Cocoa Touch Class > Language Objective-C > Create
- Xcode asks you to create a bridging header, let Xcode create that header
- Do the steps in: http://www.brianjcoleman.com/tutorial-facebook-login-in-swift/
- Add
#import <FacebookSDK/FacebookSDK.h>to the Xcode generated bridging header. - Build
回答3:
You need to add it to your target's build settings:
1.In Xcode, if you go into the build settings for your target, and scroll all the way down you'll find a "Swift Compiler - Code Generation" section.
2.Set "Objective-C Bridging Header" to <#PROJECT_NAME>Bridging-Header.h
3.Now create a Bridging-Header.h file.Import FacebookSDK/FacebookSDK.h to Bridging-Header.h.
This worked for me.Hope will work for u too :)
来源:https://stackoverflow.com/questions/27056648/how-to-import-facebooksdk-in-header-file-of-swift-ios-application