如何按字段和记录类型执行查询

how to perform a query by the field as well as the record type

我想知道是否可以不仅通过其记录类型而且通过其在数据库中的字段来搜索 CKRecord。例如,这是我现在用来获取记录的代码:

        database.performQuery(query, inZoneWithID: nil, completionHandler: { (records:[AnyObject]!, error:NSError!) in

            // Check if there's an error
            if error != nil {
                NSLog(error.localizedDescription)

            }
            else {

            }

        })

这只搜索记录类型,对于我的程序,我需要能够更深入地指定一个字段进行搜索。任何帮助将不胜感激!

CKQuery documentation 向您展示了如何构建更复杂的查询。这是一个简单的例子:

let firstName = "John"
let age = 20

let predicate = NSPredicate(format: "firstName = %@ AND age >= %@", firstName, NSNumber(integer: age))

let query = CKQuery(recordType: "Employee", predicate: predicate)