Class

CKFetchRecordChangesOperation

A CKFetchRecordChangesOperation object reports on the changed and deleted records in the specified record zone. Use this type of operation object to optimize fetch operations for locally managed sets of records. Specifically, use it when you maintain a local cache of your record data and need to synchronize that cache periodically with the server.

Overview

To get the most benefit out of a CKFetchRecordChangesOperation object, you must maintain a local cache of the records from the specified zone. Each time you fetch changes from that zone, the server provides a token that identifies your request. With each subsequent fetch request, you initialize the operation object with the token from the previous request, and the server returns only the records that changed since that request.

The blocks you assign to process the fetched records are executed serially on an internal queue managed by the operation. Your blocks must be capable of executing on a background thread, so any tasks that require access to the main thread must be redirected accordingly.

If you assign a completion block to the completionBlock property of the operation object, the completion block is called after the operation executes and returns its results to you. You can use a completion block to perform housekeeping chores related to the operation, but do not use it to process the results of the operation itself. Any completion block you specify should be prepared to handle the failure of the operation to complete its task, whether due to an error or an explicit cancellation.

Symbols

Initializing the Operation Object

init(recordZoneID: CKRecordZoneID, previousServerChangeToken: CKServerChangeToken?)

Initializes and returns an operation object configured to fetch changes in the specified record zone.

Configuring the Operation Object

var recordZoneID: CKRecordZoneID?

The ID of the record zone whose records you want to fetch.

var previousServerChangeToken: CKServerChangeToken?

The token that identifies the starting point for retrieving changes.

var desiredKeys: [String]?

The fields to fetch for the requested records.

var resultsLimit: Int

The maximum number of changed records to report with this operation object.

Processing the Operation Results

var recordChangedBlock: ((CKRecord) -> Void)?

The block to execute with the contents of a changed record.

var recordWithIDWasDeletedBlock: ((CKRecordID) -> Void)?

The block to execute with the ID of a record that was deleted.

var moreComing: Bool

A Boolean value indicating that more results are available.

Initializers

Relationships

Inherits From

See Also

Related Documentation