PFObject values may not have class: _SwiftValue

2019-05-23 13:39发布

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:

crash log - image

Any help is much appreciated to get this issue resolved. Thanks!

1条回答
戒情不戒烟
2楼-- · 2019-05-23 14:18

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()
查看更多
登录 后发表回答