ios – 如何防止Parse保存PFObject儿童?

前端之家收集整理的这篇文章主要介绍了ios – 如何防止Parse保存PFObject儿童?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正面临着Parse和iOS的一个非常普遍的问题.

我有一个类POST,具有以下结构:

> text(String)
>图像(PFFile)
> LikesUsers(String of String)
> LikesCount(Int)
>从(发布到用户的指针)

如果用户(已登录)喜欢帖子.我只是递增喜欢并将用户的Objectid添加到数组中

例如:User-2喜欢User-1的帖子.

PostObject.incrementKey("Likes")
PostObject.addObject((PFUser.currentUser()?.objectId)!,forKey: "LikesUsers")
PostObject.saveEventually()

问题在这里.我不能保存PostObject,只要它有一个指向另一个用户的指针(比登录)我收到错误

User cannot be saved unless they have been authenticated via logIn or
signUp

那么如何防止保存ParSEObject Children(“From”)

我不想使用CloudCode,我希望保持简单并使用SaveEventually来获得更好的用户体验.

解决方法

来自parse.com论坛:

When you save an object with a pointer,Parse looks at the entirety of the object and saves the fields that are “dirty” (changed since last save). It also inspects all the objects being pointed to by pointers. If your object has a pointer to PFUser and the instance of the PFUser is “dirty”,then Parse will save the object and then attempt to save the instance of the PFUser as well. My hypothesis is that somewhere in your code you are setting a value on a user and then not saving the user. This,I suspect,is the source of your error. Go through your code and look for anywhere you set a PFUser instance and make sure there’s a corresponding save. If you can’t find it at first glance,be sure to check all blocks and ensure that you are not asynchronously dirtying a user and subsequently trying to save it.

您是否尝试对发布帖子的用户进行任何更改?

原文链接:https://www.f2er.com/iOS/331388.html

猜你在找的iOS相关文章