我正在开发一个允许用户使用Facebook登录的应用程序。我的代码段使用的是swift 3 tho,但是我找不到在线转换器。快捷的3代码如下:
在示例3中,Xcode建议:
request.start(completion: ((HTTPURLResponse?, GraphRequestResult<GraphRequest>) -> Void)?)
然后程序员进入(这是整个功能):
func getUserInfo(completion: @escaping (_ : [String: Any]?, _ : Error?) -> Void) {
let request = GraphRequest(graphPath: "me", parameters: ["fields" : "id,email,picture"])
request.start { response, result in
switch result {
case .failed(let error):
completion(nil, error)
case .success (let graphResponse):
completion(graphResponse.dictionaryValue, nil)
}
}
当我开始键入:
request.start
我仅获得以下选项:
哪个给我这行代码:
request.start(completionHandler: GraphRequestBlock?)
有人可以帮我将它从Swift 3转换为Swift 5吗?谢谢!
GraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start(completionHandler: { (connection, result, error) -> Void in
if error == nil{
//everything works print the user data
if let userInfo = result as? [String: Any] {
if let email = userInfo["email"] as? String {
let firstName = userInfo["first_name"] as? String
let lastName = userInfo["last_name"] as? String
//Do your operations here.
}
}
}
})
希望有帮助!