Can I get a count of records matching CKQuery from CloudKit?

I am trying to use CKQueryOperation for this:

CKQueryOperation *o = [[CKQueryOperation alloc] initWithQuery:query];
[o setDesiredKeys:@[]];

But it still returns a lot of data that I do not need at this moment

<CKRecord: 0x79881a50; recordType=Comment, recordID=CBB7B269-47AH-406E-8934-682D31501778:(_defaultZone:__defaultOwner__), recordChangeTag=i1x8j1ey, values={
}>
{
    creatorUserRecordID -> <CKRecordID: 0x7966e9d0; _e5b178bde573ba6fee336b9ed8:(_defaultZone:__defaultOwner__)>
    lastModifiedUserRecordID -> <CKRecordID: 0x7966cdd0; _e5b178bd3e9e7a6e336b9f34ed8:(_defaultZone:__defaultOwner__)>
    creationDate -> 2014-10-31 07:20:45 +0000
    modificationDate -> 2014-10-31 07:20:45 +0000
    modifiedByDevice -> iPhone Simulator
}

I need only the number of records.

+4
source share
1 answer

Aggregation requests are not possible in CloudKit. Therefore, you should query all records and count them. To ensure that all records are returned, you need to set operation.resultsLimit to a value greater than the number, otherwise it might happen that not all records are returned.

+4
source

All Articles