致电Swift的Facebook代表

编程入门 行业动态 更新时间:2024-10-07 23:27:17
本文介绍了致电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;

  • 方法名以loginViewFetchedUserInfo开头。这一点保持不变
  • 参数是一个类型为FDBLoginView的指针,这将被转换为FBLoginView类型的可选项,因为它可以为零。约定是使它成为一个隐式解包可选,因此它将成为 FBLoginView!
  • 协议是Swift中的类型,所以用户参数将变得简单 FBGraphUser 。
  • swift方法中的第一个参数被认为只是一个内部名称,因此参数可以命名为任何东西,但为了一致性,我们将其命名为相同:loginView
  • swift方法中的第二个参数被假定为内部和外部。在目标c版本中,它们恰好相同,所以我们可以简单地使用它,Swift将使内部和外部名称成为
  • The method name starts with "loginViewFetchedUserInfo". That stays the same
  • 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!
  • Protocols are types in and of themselves in Swift, so the user parameter will become simply FBGraphUser.
  • 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"
  • 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代表

    本文发布于:2023-11-12 02:10:00,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1580199.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:代表   Swift   Facebook

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!