Search code examples
objective-cfetchcloudkit

CloudKit Batch Fetches?


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?


Solution

  • 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.