Fetching Paged Images

Fetching records in CloudKit fetch the entire record, including downloading any associated assets. This makes it not feasible to fetch many records at a time. Instead, we'll see how to fetch a subset of each record, keeping the overall size of the request small. We'll also introduce paging to request a single visible set of records at a time.

We'll also tell the request to only fetch 12 records at a time. This number should be roughly the size of a single visible page of records.

operation.resultsLimit = 12

Sorting the Results

We want the newest photo to be first in the list, so we'll add a sort option to our query. To do this, we'll have to make sure that the attribute we're sorting by (creationDate in this case) is marked as sortable in the CloudKit Dashboard.