问题
We are trying out Parse server
, and we have never used Parse SDK before.
As part of learning we tried Facebook login with Parse
, that worked good. Next we wanted to save the retrieved user information and we are stuck at saving the Profile picture
.
The Code
let pictureURL = "https://graph.facebook.com/\(facebookID)/picture?type=large&return_ssl_resources=1"
let imageData = NSData.init(contentsOf: NSURL(string: pictureURL) as! URL)
let picture = PFFile(data: imageData! as Data)
PFUser.current()?.setObject(picture, forKey: "profilePicture")
PFUser.current()?.saveInBackground()
And it crashes on the line setObject
with the following log:
Any help is much appreciated to get this issue resolved. Thanks!
回答1:
That happens when you pass Optional something to Any
.
Try this:
if let picture = PFFile(data: imageData! as Data) {
PFUser.current()?.setObject(picture, forKey: "profilePicture")
PFUser.current()?.saveInBackground()
}
Or simply this, if you are sure that picture
can never be nil:
let picture = PFFile(data: imageData! as Data)
PFUser.current()?.setObject(picture!, forKey: "profilePicture")
PFUser.current()?.saveInBackground()
来源:https://stackoverflow.com/questions/39509300/pfobject-values-may-not-have-class-swiftvalue