gpt4 book ai didi

ios - 如何消除下标错误的不明确使用?

转载 作者:行者123 更新时间:2023-11-30 13:28:54 25 4
gpt4 key购买 nike

import UIKit
import Parse
import FBSDKCoreKit
import ParseFacebookUtilsV4

class SignUpViewController: UIViewController
{


@IBOutlet weak var emailAddress: UILabel!
@IBOutlet weak var ProfileName: UILabel!
@IBOutlet weak var ProfilePic: UIImageView!
override func viewDidLoad()
{
super.viewDidLoad()

let requestParameters = ["fields": "id, email, first_name, last_name"]

let userDetails = FBSDKGraphRequest(graphPath: "me", parameters: requestParameters)

userDetails.startWithCompletionHandler { (connection, result, error:NSError!) -> Void in

if(error != nil)
{
print("\(error.localizedDescription)")
return
}

if(result != nil)
{
// The next Four lines show the same error as ambiguous Use of Subscript
let userId:String = result["id"] as! String
let userFirstName:String? = result["first_name"] as? String
let userLastName:String? = result["last_name"] as? String
let userEmail:String? = result["email"] as? String


self.ProfileName.text = userFirstName! + " " + userLastName!

let myUser:PFUser = PFUser.currentUser()!

// Save first name
if(userFirstName != nil)
{
myUser.setObject(userFirstName!, forKey: "first_name")

}

//Save last name
if(userLastName != nil)
{
myUser.setObject(userLastName!, forKey: "last_name")
}

// Save email address
if(userEmail != nil)
{
myUser.setObject(userEmail!, forKey: "email")
self.emailAddress.text = userEmail
}

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {

// Get Facebook profile picture
let userProfile = "https://graph.facebook.com/" + userId + "/picture?type=large"

let profilePictureUrl = NSURL(string: userProfile)

let profilePictureData = NSData(contentsOfURL: profilePictureUrl!)

if(profilePictureData != nil)
{
let profileFileObject = PFFile(data:profilePictureData!)
myUser.setObject(profileFileObject!, forKey: "profile_picture")
let image=UIImage(data: profilePictureData!)
self.ProfilePic.image=image

}


myUser.saveInBackgroundWithBlock({ (success:Bool, error:NSError?) -> Void in

if(success)
{
print("User details are now updated")
}

})

}

}

}
}

override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()

}

}

代码之前运行过,但在 Xcode 更新后显示此错误。

最佳答案

而不是使用

if(result != nil)

你应该这样做

if let result = result 

并使用分支内展开的值。

这样,如果有必要,你也可以沮丧,例如:

if let result = result as? NSDictionary

如果你需要告诉编译器result是一个NSDictionary。

此消息中的 ambiguously 意味着编译器无法推断 result 的类型(在 Swift 2.2 中,编译器对类型更加严格,并且不会推断出结果的类型)。不喜欢“猜测”)。

关于ios - 如何消除下标错误的不明确使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36811629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com