Call Facebook delegates in Swift

How can I name Facebook delegates using Swift? Xcode is not autocomplete, and I don't know how to 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 } 
+3
source share
1 answer

I will give one translation example and explain it so that you can translate the other delegate methods:

 - (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user: (id<FBGraphUser>)user; 
  • The method name begins with "loginViewFetchedUserInfo". It remains the same
  • The parameter is a pointer of type "FDBLoginView". This will translate to the optional FBLoginView type, as it may be zero. The convention is to make it unplanned Unwrapped Optional, so it will become FBLoginView!
  • The protocols themselves are related to Swift, so the user parameter will just become FBGraphUser .
  • The first parameter in the swift method is considered to be just the internal name, so you can call anything for the parameter, but for consistency we will call it the same: "loginView"
  • The second parameter in the fast method is considered internal and external. In the objective-c version, they turn out to be the same, so we can just use them once, and Swift will do this with both internal and external names

This leaves us with this translation:

 func loginViewFetchedUserInto(loginView : FBLoginView!, user: FBGraphUser) 
+7
source

Source: https://habr.com/ru/post/971250/


All Articles