Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instanciate FBLoginView class in swift

I try to implement Facebook SDK in an IOS Swift project, but I can't include the SDK.
Moreover, I don't know how to translate this Objective-c snippet to Swift :-

[FBLoginView class];

Someone can help me?

like image 564
cappie013 Avatar asked Jun 06 '14 18:06

cappie013


2 Answers

The easiest way I found is to add a new "Objective-C File" into your project.

It should ask you "Would you like to configure an Objective-C bridging header?" Choose Yes.

Two files will be added to your project, the Objective-C file and "(project name)-Bridging-Header.h"

Delete the empty Objective-C file you added and open (project name)-Bridging-Header.h

Add your import for the Facebook SDK into the file (using the Objective-C style import), example:

//
//  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. You do not need to add "import FacebookSDK" into your swift files. Example:

import UIKit

class LoginViewController: UIViewController {
    var fbl: FBLoginView = FBLoginView()
    // etc...
like image 92
Denny Ferrassoli Avatar answered Oct 15 '22 05:10

Denny Ferrassoli


What are you trying to do with the class?

In swift you can reference the class with .self like so:

FBLoginView.self
like image 33
Jiaaro Avatar answered Oct 15 '22 05:10

Jiaaro