user187676
user187676

Reputation:

Fetch All CKRecords of certain type

Let's say I have records of type A in the private CloudKit database. How do I fetch ALL records of that type, without specifying record IDs or a query predicate?

Upvotes: 0

Views: 359

Answers (1)

Mick MacCallum
Mick MacCallum

Reputation: 130183

CKQuery requires a non-nil predicate on initialization (see documentation), so you have to specify a predicate, even if it's always true. Ex:

let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "TheRecordType", predicate: predicate)

let operation = CKQueryOperation(query: query)
operation.queryCompletionBlock = {cursor, error in
    // done
}

CKContainer.defaultContainer().privateCloudDatabase.addOperation(operation)

Upvotes: 2

Related Questions