gpt4 book ai didi

ios - 如果 PFQuery 已经在运行,则忽略获取

转载 作者:行者123 更新时间:2023-12-01 18:55:59 25 4
gpt4 key购买 nike

如果一个已经在运行,我怎么能忽略新的提取。这是我的代码的一个示例:
因此,如果我调用 [self getParticipants] 如何确保已在运行时忽略。我唯一的解决方案是创建 BOOL 属性“inMiddleOfFetching”,但我不想为此创建另一个 BOOL 属性。有更好的解决方案吗?

- (void)getParticipants {
PFQuery *participantsQuery = [self.participantsRelation query];
[participantsQuery includeKey:@"client"];
[participantsQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (objects)
self.participants = objects;
}];
}

最佳答案

这不是更简单,而是更好,您可以使用 bolt 为查询创建单个任务,这样如果多次调用它只会运行一次,但所有调用都会同时返回值。
像这样的东西:

 @property BFTask* task;
- (BFTask *)getParticipants {
if (!_task) {
PFQuery *participantsQuery = [self.participantsRelation query];
[participantsQuery includeKey:@"client"];
_task = [participantsQuery findObjectsInBackground];
}

return _task;

}

然后得到结果:
[[self getParticipants] continueWithBlock:^id(BFTask *task) {
if(!task.error){
self.participants = task.result;
}
_task = nil; //if you want to run the query again in the future
return nil;
}];

关于ios - 如果 PFQuery 已经在运行,则忽略获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27180758/

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