Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call Facebook delegates in Swift

How can I call the Facebook delegates using Swift? Xcode doesn't autocomplete and I don't know how use it.

import UIKit

class ViewController: UIViewController,FBLoginViewDelegate {

    @IBOutlet var fbLoginView : FBLoginView

    override func viewDidLoad() {
        super.viewDidLoad()

        self.fbLoginView.delegate = self
        self.fbLoginView.readPermissions = ["public_profile", "email", "user_friends"]

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // Facebook Delegates



}
like image 675
dpbataller Avatar asked Nov 21 '25 03:11

dpbataller


1 Answers

I will give one example translation and explain it so that you should be able to translate the rest of the delegate methods:

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user: (id<FBGraphUser>)user;
  1. The method name starts with "loginViewFetchedUserInfo". That stays the same
  2. The parameter is a pointer of type "FDBLoginView" This will get translated to an optional of type FBLoginView because it can be nil. The convention is to make it an Implicitly Unwrapped Optional so it will become FBLoginView!
  3. Protocols are types in and of themselves in Swift, so the user parameter will become simply FBGraphUser.
  4. The first parameter in a swift method is assumed to be just an internal name so the parameter can be named anything but for consistency we will name it the same: "loginView"
  5. The second parameter in a swift method is assumed to be both internal and external. In the objective-c version they happen to be the same so we can simply use it once and Swift will make it both the internal and external name

This leaves us with this translation:

func loginViewFetchedUserInto(loginView : FBLoginView!, user: FBGraphUser)
like image 117
drewag Avatar answered Nov 23 '25 05:11

drewag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!