PFObject 值可能没有 class: _SwiftValue

PFObject values may not have class: _SwiftValue

我们正在试用Parse server,我们之前从未使用过Parse SDK。 作为学习的一部分,我们尝试了 Facebook login with Parse,效果很好。接下来我们想保存检索到的用户信息,我们被困在保存 Profile picture.

代码

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()

它在 setObject 行崩溃,日志如下:

非常感谢任何帮助来解决这个问题。谢谢!

当您将 Optional something 传递给 Any 时会发生这种情况。

试试这个:

    if let picture = PFFile(data: imageData! as Data) {
        PFUser.current()?.setObject(picture, forKey: "profilePicture")
        PFUser.current()?.saveInBackground()
    }

或者简单地说,如果您确定 picture 永远不会为零:

    let picture = PFFile(data: imageData! as Data)
    PFUser.current()?.setObject(picture!, forKey: "profilePicture")
    PFUser.current()?.saveInBackground()