How to import FacebookSDK in Header file of Swift iOS application

那年仲夏 提交于 2019-12-23 15:50:29

问题


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:

  1. Create a Swift project
  2. File > New > Cocoa Touch Class > Language Objective-C > Create
  3. Xcode asks you to create a bridging header, let Xcode create that header
  4. Do the steps in: http://www.brianjcoleman.com/tutorial-facebook-login-in-swift/
  5. Add #import <FacebookSDK/FacebookSDK.h> to the Xcode generated bridging header.
  6. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!