致电Swift的Facebook代表 [英] Call Facebook delegates in Swift

查看:90
本文介绍了致电Swift的Facebook代表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Swift打电话给Facebook代表? Xcode不自动完成,我不知道如何使用它。

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



}


推荐答案

我将给一个例子翻译并解释一下,以便您能够翻译其余的委托方法:

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. 方法名以loginViewFetchedUserInfo开头。这一点保持不变

  2. 参数是一个类型为FDBLoginView的指针,这将被转换为FBLoginView类型的可选项,因为它可以为零。约定是使它成为一个隐式解包可选,因此它将成为 FBLoginView!

  3. 协议是Swift中的类型,所以用户参数将变得简单 FBGraphUser

  4. swift方法中的第一个参数被认为只是一个内部名称,因此参数可以命名为任何东西,但为了一致性,我们将其命名为相同:loginView

  5. swift方法中的第二个参数被假定为内部和外部。在目标c版本中,它们恰好相同,所以我们可以简单地使用它,Swift将使内部和外部名称成为

  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)

这篇关于致电Swift的Facebook代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆