4

I try to use CKQueryOperation for this:

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

But it still returns a lot of data that I don't need in 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 a count of records.

AlKozin
  • 904
  • 8
  • 25
  • This already has been answered in: http://stackoverflow.com/questions/24191999/cloudkit-count-records – Edwin Vermeer Oct 31 '14 at 11:00
  • @EdwinVermeer, I don't want to set limits, I want to know how much records is. – AlKozin Nov 02 '14 at 10:47
  • Aggregation queries are not possible in CloudKit. So you have to query all records and count those. That comment there about setting the limit is to show that you can control the amount of records cloud kit returns. Because if you query cloudkit Apple will decide how many records it will return. When you do a query there is a chance that not all records are returned. The queryCompletionBlock returns a cursor. You will have to continue reading starting from that cursor. – Edwin Vermeer Nov 03 '14 at 06:56
  • @EdwinVermeer So, I understand. Can you advise me how you would have solved the problem: there are few tens of events, for each of them I want to find the amount of comments. In the future amount of unread comments too. Reference is backward according to Apple's recommendation: From comment to event. Can you write as an answer so I can close the question? – AlKozin Nov 03 '14 at 10:10

1 Answers1

5

Aggregation queries are not possible in CloudKit. So you have to query all records and count those. To make sure that all records will be returned, you have to set operation.resultsLimit to a value larger than the count otherwise it could happen that not all records are returned.

Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58