2

Using CloudKit, how can I fetch my results in batches?

I know that the default fetch limit it 100 results. So who do I then fetch the subsequent 100 results?

halfer
  • 19,824
  • 17
  • 99
  • 186
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253

1 Answers1

2

The number of records returned by CloudKit is not fixed. CloudKit has a mechanism for deciding how many records to return. It looks like it's currently 100, but it could change depending on the current load on Cloudkit. It is possible to set this to a fixed number on the CKQueryOperation object. The default is:

operation.resultsLimit = CKQueryOperationMaximumResults;

The documentations for this property says: When using that value, the server chooses a limit that aims to provide an optimal number of results that returns as many records as possible while minimizing delays in receiving those records. However, if you know that you want to process a fixed number of results, change the value of this property accordingly.

The CKQueryOperation will return a cursor in the queryCompletionBlock which can then be used to execute an other CKQueryOperation to fetch the next block.

Alex Reynolds
  • 6,264
  • 4
  • 26
  • 42
Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58
  • Gotcha! Thanks Edwin, I hadn't realized cursors were what I needed to look at, makes much more sense now. – Josh Kahane Nov 25 '14 at 21:32
  • I've found today that whilst the cursor indeed allows you to keep getting more records in batches of 100, there is an upper limit of 10,000 to how many are retrieved. I don't know how to go beyond this. I need to be able to traverse all records in a table (and there are a lot). I've tried setting the result limit to (say) 20,000 however this produced results with varying number of records, usually around 101. – PKCLsoft Jun 27 '17 at 05:14