PFObject values may not have class: _SwiftValue

吃可爱长大的小学妹 提交于 2020-01-02 15:05:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!