Swift 3 created error for Facebook Graph Request

瘦欲@ 提交于 2020-01-05 04:55:32

问题


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)!
    }

回答1:


You have to convert "result" into a dictionary. For example:

let r: [String: Any]? = result as? [String: Any]

...and continue



来源:https://stackoverflow.com/questions/39494003/swift-3-created-error-for-facebook-graph-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!