我刚开始通过以下教程和在线课程学习Swift。
由于此错误,我无法保存解析Facebook用户个人资料图片:
无法指定类型' NSData的值!'类型为' AnyObject?'
我的代码:
override func viewDidLoad() {
super.viewDidLoad()
var user = PFUser.currentUser()
var accessToken = FBSDKAccessToken.currentAccessToken().tokenString
let url = NSURL(string: "https://graph.facebook.com/me/picture?type=large&return_ssl_resources=1&access_token="+accessToken)
let urlRequest = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue(),
completionHandler: {
response, data, error in
let image = UIImage(data: data)
self.profilePic.image = image
user["image"] = data -> Cannot assign a value of type 'NSData!' to a value of type 'AnyObject?'
user.save()
答案 0 :(得分:0)
您应该使用图像数据实例化PFFile:
var imageFile = PFFile.fileWithData(data)
将其保存在后台,然后在保存回调中设置用户[“image”] = imageFile