gpt4 book ai didi

ios - PFQuery FindObjectsInBackground 返回 0

转载 作者:可可西里 更新时间:2023-11-01 02:59:25 24 4
gpt4 key购买 nike

在我的 UIViewController 中,我试图查询我的解析服务器,但我一直得到 0 的返回值,尽管我 100% 知道这个类中确实有对象。有什么想法吗?

 PFQuery *query = [PFQuery queryWithClassName:@"General"];

int i;
for (i = 0; i < [follows count]; i++) {
[query whereKey:@"Session" containedIn:follows];
}
query.cachePolicy = kPFCachePolicyCacheThenNetwork;

[query orderByDescending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
// it never gets here...
NSLog(@"OBJECTS%@", objects);
if (!error) {
NSLog(@"Successfully retrieved %lu objects.", (unsigned long)objects.count);
for (PFObject *object in objects) {
NSLog(@"%@", object.objectId);
}

// [self gotoMain];
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];

它告诉我没有错误,它在我的控制台中成功检索了 0 个对象。

最佳答案

正如其他人已经建议的那样,我会先做最简单的查询:

PFQuery *query = [PFQuery queryWithClassName:@"General"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"Successfully retrieved %lu objects.", (unsigned long)objects.count);
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];

如果执行无误,返回0个对象,dashboard显示有应该返回的对象,肯定是类名错误。所以请仔细检查类(class)名称,例如拼写。

如果返回对象,则您的过滤器一定是错误的。你的 for 在任何地方都是错误的,原因有两个:
1) for 循环执行了 follows.count - 次,但它总是执行相同的指令,因为未使用 index。我猜你想写(但这也是错误的)

 for (i = 0; i < [follows count]; i++) {
[query whereKey:@"Session" containedIn:follows[i]];
}

2) 这是错误的,因为您只能有一个过滤器 whereKey:containedIn:。正如 DevKyle 所提到的,这个单一过滤器被覆盖 follows.count-1 - 次,并且只使用最后一个过滤器。
我猜你想要像单个过滤器的逻辑 OR 之类的东西。如果是这样,您必须展平数组,即制作一个包含 follows[i] 中所有元素的单个数组 NSArray *flattenedFollows,请参阅 here然后设置一个过滤器

 [query whereKey:@"Session" containedIn: flattenedFollows];  

编辑:
最后一个想法:如果您的查询是正确的(除了 for 循环之外)并且无论如何都没有返回任何对象,则可能是您无权访问它们。因此,请检查这些记录的 ACL 字段是否具有正确的访问权限。

关于ios - PFQuery FindObjectsInBackground 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46167647/

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