gpt4 book ai didi

ios - 为什么通过保存 PFUser 对象来保存 PFRelation?

转载 作者:行者123 更新时间:2023-11-29 10:34:21 24 4
gpt4 key购买 nike

所以我无法理解 PFRelation 如何保存,我有这段代码:

PFUser *user = [PFUser currentUser];
PFRelation *relation = [user relationForKey:@"likes"];
[relation addObject:post];
[user saveInBackground];

为什么更新用户即 [user saveInBackground] 更新该用户的 PFRelation 字段“喜欢”?这是使用单个 API 调用还是 [relation addObject: post];还需要 API 调用?

如有任何帮助,我们将不胜感激。

谢谢

最佳答案

在您的情况下,使用了 1 个 API 请求。

看看 PFObject [直接来自 Parse.com]:

// Create the post
PFObject *myPost = [PFObject objectWithClassName:@"Post"];
myPost[@"title"] = @"I'm Hungry";
myPost[@"content"] = @"Where should we go for lunch?";

// Create the comment
PFObject *myComment = [PFObject objectWithClassName:@"Comment"];
myComment[@"content"] = @"Let's do Sushirrito.";

// Add a relation between the Post and Comment
myComment[@"parent"] = myPost;

这里您正在为 PFObject 设置属性或属性,但是在您保存它之前什么都不会发生,您可以对对象做任何事情,比如更改它,更新它,这无关紧要,但后端明智,它不会更新除非你告诉它保存在哪里发挥作用:

[myComment saveInBackground];

简而言之,您可以整天添加关系、指针和大量参数,但除非您告诉它发生,否则什么也不会发生:[saveInBackground];

因为您使其与用户直接相关,所以它会按照您的指示将其保存给该用户。因为您指定了与用户的关系,所以一旦您保存了用户属性,该关系也将被保存。但是,这不会创建更多 API 请求。

关于ios - 为什么通过保存 PFUser 对象来保存 PFRelation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27890110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com