简体   繁体   English

快速实例化 FBLoginView 类

[英]Instanciate FBLoginView class in swift

I try to implement Facebook SDK in an IOS Swift project, but I can't include the SDK.我尝试在 IOS Swift 项目中实现Facebook SDK ,但我无法包含 SDK。
Moreover, I don't know how to translate this Objective-c snippet to Swift :-此外,我不知道如何将这个 Objective-c 片段翻译成 Swift :-

[FBLoginView class];

Someone can help me?有人可以帮助我吗?

The easiest way I found is to add a new "Objective-C File" into your project.我发现的最简单的方法是在您的项目中添加一个新的“Objective-C 文件”。

It should ask you " Would you like to configure an Objective-C bridging header? " Choose Yes .它应该会问你“你想配置一个 Objective-C 桥接头吗? ”选择Yes

Two files will be added to your project, the Objective-C file and " (project name)-Bridging-Header.h "两个文件将添加到您的项目中,Objective-C 文件和“ (项目名称)-Bridging-Header.h

Delete the empty Objective-C file you added and open (project name)-Bridging-Header.h删除你添加的空Objective-C文件并打开(项目名称)-Bridging-Header.h

Add your import for the Facebook SDK into the file (using the Objective-C style import), example:将 Facebook SDK 的导入添加到文件中(使用 Objective-C 样式导入),例如:

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//

#import <FacebookSDK/FacebookSDK.h>

Save the header file and you can now access Facebook SDK in your swift code.保存头文件,您现在可以在 swift 代码中访问 Facebook SDK。 You do not need to add "import FacebookSDK" into your swift files.无需在 swift 文件中添加“导入 FacebookSDK”。 Example:例子:

import UIKit

class LoginViewController: UIViewController {
    var fbl: FBLoginView = FBLoginView()
    // etc...

What are you trying to do with the class?你想用课堂做什么?

In swift you can reference the class with .self like so:在 swift 中,您可以像这样使用.self引用类:

FBLoginView.self

Believe with the latest updates from Facebook, the imports for the Header File are:相信随着 Facebook 的最新更新,头文件的导入是:

#import <FBSDKCoreKit/FBSDKCoreKit.h> 
#import <FBSDKLoginKit/FBSDKLoginKit.h> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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