Instantiates and returns a sample query.
- iOS 8.0+
- watchOS 2.0+
A predicate that limits the results returned by the query. Pass
nilto receive all the samples of the specified type.
The maximum number of samples returned by the query. If you want to return all matching samples, use
Query No Limit
An array of sort descriptors that specify the order of the results returned by this query. Pass
nilif you don’t need the results in a specific order.
A block that is called when the query finishes executing.
This block takes the following parameters:
A reference to the query that called this block.
An array containing the samples found by the query, or
nilif an error occurs.
If an error occurs, this parameter contains an object describing the error. Otherwise, its value is
A newly initialized sample query object.
After instantiating the query, call the
execute(_:) method to run this query. Queries run on an anonymous background queue. As soon as the query is complete, the results handler is executed on the background queue. You typically dispatch these results to the main queue to update the user interface.