PFObject 值可能没有类:

编程入门 行业动态 更新时间:2024-10-28 21:29:27
本文介绍了PFObject 值可能没有类:_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 = "graph.facebook/\(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 值可能没有类:

本文发布于:2023-11-26 04:49:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632696.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PFObject

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!