PFObject 值可能没有类:_SwiftValue [英] PFObject values may not have class: _SwiftValue
问题描述
我们正在试用 Parse server
,我们之前从未使用过 Parse SDK.作为学习的一部分,我们尝试了 Facebook 使用 Parse 登录
,效果很好.接下来我们想保存检索到的用户信息,但我们一直在保存个人资料图片
.
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
.
代码
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
行上崩溃,日志如下:
And it crashes on the line setObject
with the following log:
非常感谢您帮助解决此问题.谢谢!
Any help is much appreciated to get this issue resolved. Thanks!
推荐答案
当您将 Optional 对象传递给 Any
时会发生这种情况.
That happens when you pass Optional something to Any
.
试试这个:
if let picture = PFFile(data: imageData! as Data) {
PFUser.current()?.setObject(picture, forKey: "profilePicture")
PFUser.current()?.saveInBackground()
}
或者简单的这个,如果你确定 picture
永远不会为零:
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()
这篇关于PFObject 值可能没有类:_SwiftValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!