iosswiftfacebook-sdk-3.0

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?


Solution

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