以前工作的代码现在失败了......
我从我的应用中提取了以下几行以显示问题
PFQuery *query = [PFQuery queryWithClassName:@"EBInspection"];
[query setLimit:1000];
[query whereKey:@"ParentID" equalTo:@"OdP1ZnYHib"];
NSLog(@"Count = %i", [query findObjects].count);
这些行在EBInspection表中找到34个匹配的行,但是有86行,我已使用Parse仪表板确认并设置了查询。我还编写了以下代码来测试所有行,它返回86 !!
PFQuery *query = [PFQuery queryWithClassName:@"EBInspection"];
[query setLimit:1000];
[query setSkip:2000];
int nIns = 0;
for (PFObject *obj in [query findObjects]) {
if ([obj[@"ParentID"] isEqualToString:@"OdP1ZnYHib"]) nIns += 1;
}
NSLog(@"count= %i",nIns);
确实很奇怪。看起来某种数据损坏会混淆查询。任何建议都非常感谢。
答案 0 :(得分:2)
使用countObjectsInBackgroundWithBlock
代替findObjects
,然后自行计算结果。请尝试以下
目标-C
PFQuery *query = [PFQuery queryWithClassName:@"GameScore"];
[query whereKey:@"playername" equalTo:@"Sean Plott"];
[query countObjectsInBackgroundWithBlock:^(int count, NSError *error) {
if (!error) {
// The count request succeeded. Log the count
NSLog(@"Sean has played %d games", count);
} else {
// The request failed
}
}];
夫特
var query = PFQuery(className:"GameScore")
query.whereKey("playerName", equalTo:"Sean Plott")
query.countObjectsInBackgroundWithBlock {
(count: Int32, error: NSError?) -> Void in
if error == nil {
print("Sean has played \(count) games")
}
}
有关计数操作的更多信息see my detailed explanation here