Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift:解析中的长查询(或/和条件)_Ios_Objective C_Iphone_Swift_Parse Platform - Fatal编程技术网

Ios Swift:解析中的长查询(或/和条件)

Ios Swift:解析中的长查询(或/和条件),ios,objective-c,iphone,swift,parse-platform,Ios,Objective C,Iphone,Swift,Parse Platform,我需要使用Parse SDK执行 我的代码: func retrieveObjects() { let conditions: [String] = ..... let query: PFQuery = self.generateCompoundQueryFromConditions(conditions) query.findObjectsInBackgroundWithBlock { (objs:[AnyObject]?,error: NSError?) -> Void i

我需要使用Parse SDK执行

我的代码:

func retrieveObjects() {
  let conditions: [String] = .....
  let query: PFQuery = self.generateCompoundQueryFromConditions(conditions)
  query.findObjectsInBackgroundWithBlock { (objs:[AnyObject]?,error: NSError?) -> Void in
      NSLog("\(objs)")
  }
}

private func generateCompoundQueryFromConditions(conditions: [String]) -> PFQuery {
    var queries: [PFQuery] = []
    for condition: String in conditions {
        var query = PFQuery(className:"MyClassName")
        query.whereKey("objectId", equalTo: condition)
        queries.append(query)
    }
    return PFQuery.orQueryWithSubqueries(queries)
}
条件计数->24
代码工作得很好,但我遇到以下错误:

 [Error]: too many $or clauses (Code: 154, Version: 1.7.4)
有没有一种方法可以使用多种或多种条件进行查询

更新 我还尝试使用NSPredicate:

private func generateQueryWithPredicateFromConditions(conditions: [String]) -> PFQuery {
    var predicates: [NSPredicate] = []
    for condition in conditions {
        predicates.append(NSPredicate(format: "objectId = %@", condition))
    }
    let predicate = NSCompoundPredicate.orPredicateWithSubpredicates(predicates)
    return PFQuery(className: "MyClassName", predicate: predicate)
}
现在的错误是:

'This query is too complex. It had an OR with >4 subpredicates after normalization.'

所以,使用N-OR条件,我将执行N/4+N%4 PFQuery,然后合并结果。可能是一个解决方案吗?

我自己用这种方式解决了,希望能帮助到别人:

let query = PFQuery(className: "MyClassName")
query.whereKey("objectId", containedIn: conditions)
query.findObjectsInBackgroundWithBlock { (objs:[AnyObject]?,error: NSError?) -> Void in
    NSLog("\(objs)")
}

在predicate.no Keybur中使用“objectId==%@,=%@是OK这工作非常好,当在包含110万条记录的表中搜索1.5k个条件时,经过测试,它在2秒内返回1k个结果。