Swift 3为Facebook图形请求创建了错误 [英] Swift 3 created error for Facebook Graph Request
问题描述
我被要求更新到swift 3,现在我的facebook图表请求无法编译.它一直在给我错误类型为"Any?"的错误值.没有成员对象".它以String!)!的形式在result.object(forKey:"email")上引发此错误.在迅速解决三件事之前,它工作正常,并且从未遇到过该错误.我不确定如何解决它,因为我无法阅读所有新文档.
I was asked to update to swift 3 and now my facebook graph request won't compile. It keeps giving me the error Value of type "Any?" has no member 'object'. It throws this error on result.object(forKey: "email") as String!)!. Before swift three it worked properly and never through that error. I am not sure how to fix it as I have not been able to read through all the new documentation.
let UserEmail = FBSDKGraphRequest.init(graphPath: "me", parameters: ["fields":"email"]).start { (connection, result, error) -> Void in
let strEmail: String = (result.object(forKey: "email") as? String)!
}
推荐答案
您必须将结果"转换为字典.例如:
You have to convert "result" into a dictionary. For example:
让r:[String:Any]? =结果为? [String:Any]
let r: [String: Any]? = result as? [String: Any]
...然后继续
这篇关于Swift 3为Facebook图形请求创建了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!