Instance Method

performQuery:inZoneWithID:completionHandler:

Searches the specified zone asynchronously for records that match the query parameters.

Declaration

- (void)performQuery:(CKQuery *)query inZoneWithID:(CKRecordZoneID *)zoneID completionHandler:(void (^)(NSArray<CKRecord *> *results, NSError *error))completionHandler;

Parameters

query

The query object containing the parameters for the search. This method throws an exception if this parameter is nil. For information about how to construct queries, see CKQuery.

zoneID

The ID of the zone to search. Search results are limited to records in the specified zone. Specify nil to search the default zone of the database.

completionHandler

The block to execute with the search results. Your block must be capable of running on any thread of the app and must take the following parameters:

results

An array containing zero or more CKRecord objects. The returned records correspond to the records in the specified zone that match the parameters of the query.

error

An error object, or nil if the query was completed successfully. Use the information in the error object to determine whether a problem has a workaround.

Discussion

Use this method to execute searches against the current database. Do not use this method when the number of returned records is potentially more than a few hundred records; when more records are needed, create an execute a CKQueryOperation instead of calling performQuery:inZoneWithID:completionHandler: on the CKDatabase. For efficiency, all queries automatically limit the number of returned records based on current conditions. If your query hits the maximum value, this method returns only the first portion of the overall results. The number of returned records should be sufficient in most cases, but to get the entire set of records you must create and execute a CKQueryOperation object instead. Query operations also return a maximum number of results, but when they do, they provide a cursor object that you can use to fetch the next batch of results.

You can search any content that is represented by a CKRecord object, including user records. You cannot use this method to search for CKSubscription or CKRecordZone objects.

See Also