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更新后它显示此错误。
答案 0 :(得分:0)
而不是使用
if(result != nil)
你应该做
if let result = result
并使用分支内的解包值。
如果有必要,你也可以贬低,如:
if let result = result as? NSDictionary
如果您需要告诉编译器result
是NSDictionary。
此消息中ambiguous
的含义是编译器无法推断result
的类型(在Swift 2.2中,编译器对类型更严格,并且没有&#t; t喜欢"猜测")。