类型 'Any' 在 Facebook SDK 中没有下标成员
Type 'Any' Has No Subscript Members in Facebook SDK
我在我的应用程序中集成了 Facebook 登录 SDK,但我是新手。我实现了它,但现在我想收到电子邮件。因此,按照教程,我创建了与教程展示的相同的函数。
函数如下:
func fetchProfile()
{
print("Fetch Profile")
let parameters: [String : Any] = ["fields" : "email, first_name, last_name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).start(completionHandler: {
(connection, result, error) -> Void in
if error != nil {
print(error!)
return
}
if let email = result["email"] as? String {
print(email)
}
}
}
所以,程序员在那里使用 Swift 3 而我在这里使用 Swift 4,所以它会产生任何问题吗?而且,它说 Type "Any" has no subscript members
其中 if let email =
是写的。如何解决?
将结果转换为 [String:Any]
if let resultDict = result as? [String:Any]{
if let email = resultDict["email"] as? String {
print(email)
}
}
我在我的应用程序中集成了 Facebook 登录 SDK,但我是新手。我实现了它,但现在我想收到电子邮件。因此,按照教程,我创建了与教程展示的相同的函数。
函数如下:
func fetchProfile()
{
print("Fetch Profile")
let parameters: [String : Any] = ["fields" : "email, first_name, last_name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).start(completionHandler: {
(connection, result, error) -> Void in
if error != nil {
print(error!)
return
}
if let email = result["email"] as? String {
print(email)
}
}
}
所以,程序员在那里使用 Swift 3 而我在这里使用 Swift 4,所以它会产生任何问题吗?而且,它说 Type "Any" has no subscript members
其中 if let email =
是写的。如何解决?
将结果转换为 [String:Any]
if let resultDict = result as? [String:Any]{
if let email = resultDict["email"] as? String {
print(email)
}
}