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.

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

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...