Query

public struct Query<T> : Encodable, Equatable where T : ParseObject
extension Query: Queryable

The Query class defines a query that is used to query for ParseObjects.

  • An enum that determines the order to sort the results based on a given key.

    See more

    Declaration

    Swift

    public enum Order : Encodable, Equatable

    Parameters

    key

    The key to order by.

  • Create an instance with a variadic amount constraints.

    Declaration

    Swift

    public init(_ constraints: QueryConstraint...)

    Parameters

    constraints

    A variadic amount of zero or more QueryConstraint‘s.

  • Create an instance with an array of constraints.

    Declaration

    Swift

    public init(_ constraints: [QueryConstraint])

    Parameters

    constraints

    An array of QueryConstraint‘s.

  • Declaration

    Swift

    public static func == (lhs: Query<T>, rhs: Query<T>) -> Bool
  • Add any amount of variadic constraints.

    Declaration

    Swift

    public func `where`(_ constraints: QueryConstraint...) -> Query<T>

    Parameters

    constraints

    A variadic amount of zero or more QueryConstraint‘s.

  • A limit on the number of objects to return. The default limit is 100, with a maximum of 1000 results being returned at a time.

    Note

    If you are calling find with limit = 1, you may find it easier to use first instead.

    Declaration

    Swift

    public func limit(_ value: Int) -> Query<T>

    Parameters

    value

    n number of results to limit to.

  • The number of objects to skip before returning any. This is useful for pagination. Default is to skip zero results.

    Declaration

    Swift

    public func skip(_ value: Int) -> Query<T>

    Parameters

    value

    n number of results to skip.

  • Changes the read preference that the backend will use when performing the query to the database.

    Declaration

    Swift

    public func readPreference(_ readPreference: String?,
                               includeReadPreference: String? = nil,
                               subqueryReadPreference: String? = nil) -> Query<T>

    Parameters

    readPreference

    The read preference for the main query.

    includeReadPreference

    The read preference for the queries to include pointers.

    subqueryReadPreference

    The read preference for the sub queries.

  • Make the query include ParseObjects that have a reference stored at the provided keys.

    Declaration

    Swift

    public func include(_ keys: String...) -> Query<T>

    Parameters

    keys

    A variadic list of keys to load child ParseObjects for.

  • Make the query include ParseObjects that have a reference stored at the provided keys.

    Declaration

    Swift

    public func include(_ keys: [String]) -> Query<T>

    Parameters

    keys

    An array of keys to load child ParseObjects for.

  • Includes all nested ParseObjects.

    Warning

    Requires Parse Server 3.0.0+

    Declaration

    Swift

    public func includeAll() -> Query<T>
  • Exclude specific keys for a ParseObject. Default is to nil.

    Declaration

    Swift

    public func exclude(_ keys: [String]?) -> Query<T>

    Parameters

    keys

    An arrays of keys to exclude.

  • Make the query restrict the fields of the returned ParseObjects to include only the provided keys. If this is called multiple times, then all of the keys specified in each of the calls will be included.

    Declaration

    Swift

    public func select(_ keys: String...) -> Query<T>

    Parameters

    keys

    A variadic list of keys include in the result.

  • Make the query restrict the fields of the returned ParseObjects to include only the provided keys. If this is called multiple times, then all of the keys specified in each of the calls will be included.

    Declaration

    Swift

    public func select(_ keys: [String]) -> Query<T>

    Parameters

    keys

    An array of keys to include in the result.

  • An enum that determines the order to sort the results based on a given key.

    Declaration

    Swift

    public func order(_ keys: [Order]?) -> Query<T>

    Parameters

    keys

    An array of keys to order by.

  • Executes a distinct query and returns unique values. Default is to nil.

    Declaration

    Swift

    public func distinct(_ key: String?) -> Query<T>

    Parameters

    keys

    A distinct key.

  • A variadic list of fields to receive when receiving a ParseLiveQuery.

    Suppose the ParseObject Player contains three fields name, id and age. If you are only interested in the change of the name field, you can set query.fields to “name”. In this situation, when the change of a Player ParseObject fulfills the subscription, only the name field will be sent to the clients instead of the full Player ParseObject.

    Warning

    This is only for ParseLiveQuery.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
    public func fields(_ keys: String...) -> Query<T>

    Parameters

    keys

    A variadic list of fields to receive back instead of the whole ParseObject.

  • A list of fields to receive when receiving a ParseLiveQuery.

    Suppose the ParseObject Player contains three fields name, id and age. If you are only interested in the change of the name field, you can set query.fields to “name”. In this situation, when the change of a Player ParseObject fulfills the subscription, only the name field will be sent to the clients instead of the full Player ParseObject.

    Warning

    This is only for ParseLiveQuery.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
    public func fields(_ keys: [String]) -> Query<T>

    Parameters

    keys

    An array of fields to receive back instead of the whole ParseObject.

ParseLiveQuery - Subscribe

  • Registers the query for live updates, using the default subscription handler, and the default ParseLiveQuery client. Suitable for ObjectObserved as the subscription can be used as a SwiftUI publisher. Meaning it can serve indepedently as a ViewModel in MVVM.

    Declaration

    Swift

    var subscribe: Subscription<ResultType>? { get }
  • Registers the query for live updates, using the default subscription handler, and a specific ParseLiveQuery client. Suitable for ObjectObserved as the subscription can be used as a SwiftUI publisher. Meaning it can serve indepedently as a ViewModel in MVVM.

    Declaration

    Swift

    func subscribe(_ client: ParseLiveQuery) throws -> Subscription<ResultType>

    Parameters

    client

    A specific client.

    Return Value

    The subscription that has just been registered

  • Registers a query for live updates, using a custom subscription handler.

    Declaration

    Swift

    static func subscribe<T>(_ handler: T) throws -> T where T : ParseSubscription

    Parameters

    handler

    A custom subscription handler.

    Return Value

    Your subscription handler, for easy chaining.

  • Registers a query for live updates, using a custom subscription handler.

    Declaration

    Swift

    static func subscribe<T>(_ handler: T, client: ParseLiveQuery) throws -> T where T : ParseSubscription

    Parameters

    handler

    A custom subscription handler.

    client

    A specific client.

    Return Value

    Your subscription handler, for easy chaining.

  • Registers the query for live updates, using the default subscription handler, and the default ParseLiveQuery client.

    Declaration

    Swift

    var subscribeCallback: SubscriptionCallback<ResultType>? { get }
  • Registers the query for live updates, using the default subscription handler, and a specific ParseLiveQuery client.

    Declaration

    Swift

    func subscribeCallback(_ client: ParseLiveQuery) throws -> SubscriptionCallback<ResultType>

    Parameters

    client

    A specific client.

    Return Value

    The subscription that has just been registered.

ParseLiveQuery - Unsubscribe

ParseLiveQuery - Update

  • Updates an existing subscription with a new query on the default ParseLiveQuery client. Upon completing the registration, the subscribe handler will be called with the new query.

    Declaration

    Swift

    func update<T>(_ handler: T) throws where T : ParseSubscription

    Parameters

    handler

    The specific handler to update.

  • Updates an existing subscription with a new query on a specific ParseLiveQuery client. Upon completing the registration, the subscribe handler will be called with the new query.

    Declaration

    Swift

    func update<T>(_ handler: T, client: ParseLiveQuery) throws where T : ParseSubscription

    Parameters

    handler

    The specific handler to update.

    client

    A specific client.

Queryable - Combine

  • Finds objects asynchronously and publishes when complete.

    Declaration

    Swift

    func findPublisher(options: API.Options = []) -> Future<[ResultType], ParseError>

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    A publisher that eventually produces a single value and then finishes or fails.

  • Finds objects asynchronously and publishes when complete.

    Declaration

    Swift

    func findPublisher(explain: Bool,
                       hint: String? = nil,
                       options: API.Options = []) -> Future<AnyCodable, ParseError>

    Parameters

    explain

    Used to toggle the information on the query plan.

    hint

    String or Object of index that should be used when executing query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    A publisher that eventually produces a single value and then finishes or fails.

  • Gets an object asynchronously and publishes when complete.

    Declaration

    Swift

    func firstPublisher(options: API.Options = []) -> Future<ResultType, ParseError>

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    A publisher that eventually produces a single value and then finishes or fails.

  • Gets an object asynchronously and publishes when complete.

    Declaration

    Swift

    func firstPublisher(explain: Bool,
                        hint: String? = nil,
                        options: API.Options = []) -> Future<AnyCodable, ParseError>

    Parameters

    explain

    Used to toggle the information on the query plan.

    hint

    String or Object of index that should be used when executing query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    A publisher that eventually produces a single value and then finishes or fails.

  • Count objects asynchronously and publishes when complete.

    Declaration

    Swift

    func countPublisher(options: API.Options = []) -> Future<Int, ParseError>

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    A publisher that eventually produces a single value and then finishes or fails.

  • Count objects asynchronously and publishes when complete.

    Declaration

    Swift

    func countPublisher(explain: Bool,
                        hint: String? = nil,
                        options: API.Options = []) -> Future<AnyCodable, ParseError>

    Parameters

    explain

    Used to toggle the information on the query plan.

    hint

    String or Object of index that should be used when executing query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    A publisher that eventually produces a single value and then finishes or fails.

  • Executes an aggregate query asynchronously and publishes when complete.

    Requires

    .useMasterKey has to be available and passed as one of the set of options.

    Declaration

    Swift

    func aggregatePublisher(_ pipeline: AggregateType,
                            options: API.Options = []) -> Future<[ResultType], ParseError>

    Parameters

    pipeline

    A pipeline of stages to process query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    A publisher that eventually produces a single value and then finishes or fails.

Queryable

  • Finds objects synchronously based on the constructed query and sets an error if there was one.

    Throws

    An error of type ParseError.

    Declaration

    Swift

    public func find(options: API.Options = []) throws -> [ResultType]

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    Returns an array of ParseObjects that were found.

  • Finds objects synchronously based on the constructed query and sets an error if there was one.

    Throws

    An error of type ParseError.

    Declaration

    Swift

    public func find(explain: Bool, hint: String? = nil, options: API.Options = []) throws -> AnyCodable

    Parameters

    explain

    Used to toggle the information on the query plan.

    hint

    String or Object of index that should be used when executing query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    Returns a dictionary of AnyResultType that is the JSON response of the query.

  • Finds objects asynchronously and calls the given block with the results.

    Declaration

    Swift

    public func find(options: API.Options = [], callbackQueue: DispatchQueue = .main,
                     completion: @escaping (Result<[ResultType], ParseError>) -> Void)

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    callbackQueue

    The queue to return to after completion. Default value of .main.

    completion

    The block to execute. It should have the following argument signature: (Result<[ResultType], ParseError>).

  • Finds objects asynchronously and calls the given block with the results.

    Declaration

    Swift

    public func find(explain: Bool, hint: String? = nil, options: API.Options = [],
                     callbackQueue: DispatchQueue = .main,
                     completion: @escaping (Result<AnyCodable, ParseError>) -> Void)

    Parameters

    explain

    Used to toggle the information on the query plan.

    hint

    String or Object of index that should be used when executing query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    callbackQueue

    The queue to return to after completion. Default value of .main.

    completion

    The block to execute. It should have the following argument signature: (Result<AnyCodable, ParseError>).

  • Gets an object synchronously based on the constructed query and sets an error if any occurred.

    Warning

    This method mutates the query. It will reset the limit to 1.

    Throws

    An error of type ParseError.

    Declaration

    Swift

    public func first(options: API.Options = []) throws -> ResultType?

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    Returns a ParseObject, or nil if none was found.

  • Gets an object synchronously based on the constructed query and sets an error if any occurred.

    Warning

    This method mutates the query. It will reset the limit to 1.

    Throws

    An error of type ParseError.

    Declaration

    Swift

    public func first(explain: Bool, hint: String? = nil, options: API.Options = []) throws -> AnyCodable

    Parameters

    explain

    Used to toggle the information on the query plan.

    hint

    String or Object of index that should be used when executing query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    Returns a dictionary of AnyResultType that is the JSON response of the query.

  • Gets an object asynchronously and calls the given block with the result.

    Warning

    This method mutates the query. It will reset the limit to 1.

    Declaration

    Swift

    public func first(options: API.Options = [], callbackQueue: DispatchQueue = .main,
                      completion: @escaping (Result<ResultType, ParseError>) -> Void)

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    callbackQueue

    The queue to return to after completion. Default value of .main.

    completion

    The block to execute. It should have the following argument signature: (Result<ParseObject, ParseError>).

  • Gets an object asynchronously and calls the given block with the result.

    Warning

    This method mutates the query. It will reset the limit to 1.

    Declaration

    Swift

    public func first(explain: Bool, hint: String? = nil, options: API.Options = [],
                      callbackQueue: DispatchQueue = .main,
                      completion: @escaping (Result<AnyCodable, ParseError>) -> Void)

    Parameters

    explain

    Used to toggle the information on the query plan.

    hint

    String or Object of index that should be used when executing query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    callbackQueue

    The queue to return to after completion. Default value of .main.

    completion

    The block to execute. It should have the following argument signature: (Result<ParseObject, ParseError>).

  • Counts objects synchronously based on the constructed query and sets an error if there was one.

    Throws

    An error of type ParseError.

    Declaration

    Swift

    public func count(options: API.Options = []) throws -> Int

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    Returns the number of ParseObjects that match the query, or -1 if there is an error.

  • Counts objects synchronously based on the constructed query and sets an error if there was one.

    Throws

    An error of type ParseError.

    Declaration

    Swift

    public func count(explain: Bool, hint: String? = nil, options: API.Options = []) throws -> AnyCodable

    Parameters

    explain

    Used to toggle the information on the query plan.

    hint

    String or Object of index that should be used when executing query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    Returns a dictionary of AnyResultType that is the JSON response of the query.

  • Counts objects asynchronously and calls the given block with the counts.

    Declaration

    Swift

    public func count(options: API.Options = [], callbackQueue: DispatchQueue = .main,
                      completion: @escaping (Result<Int, ParseError>) -> Void)

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    callbackQueue

    The queue to return to after completion. Default value of .main.

    completion

    The block to execute. It should have the following argument signature: (Result<Int, ParseError>)

  • Counts objects asynchronously and calls the given block with the counts.

    Declaration

    Swift

    public func count(explain: Bool, hint: String? = nil, options: API.Options = [],
                      callbackQueue: DispatchQueue = .main,
                      completion: @escaping (Result<AnyCodable, ParseError>) -> Void)

    Parameters

    explain

    Used to toggle the information on the query plan.

    hint

    String or Object of index that should be used when executing query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    callbackQueue

    The queue to return to after completion. Default value of .main.

    completion

    The block to execute. It should have the following argument signature: (Result<Int, ParseError>).

  • Executes an aggregate query asynchronously and calls the given.

    Requires

    .useMasterKey has to be available and passed as one of the set of options.

    Throws

    An error of type ParseError.

    Warning

    This hasn’t been tested thoroughly.

    Declaration

    Swift

    public func aggregate(_ pipeline: AggregateType,
                          options: API.Options = []) throws -> [ResultType]

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    Returns the ParseObjects that match the query.

  • Executes an aggregate query asynchronously and calls the given.

    Requires

    .useMasterKey has to be available and passed as one of the set of options.

    Warning

    This hasn’t been tested thoroughly.

    Declaration

    Swift

    public func aggregate(_ pipeline: AggregateType,
                          options: API.Options = [],
                          callbackQueue: DispatchQueue = .main,
                          completion: @escaping (Result<[ResultType], ParseError>) -> Void)

    Parameters

    pipeline

    A pipeline of stages to process query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    callbackQueue

    The queue to return to after completion. Default value of .main.

    completion

    The block to execute. It should have the following argument signature: (Result<[ResultType], ParseError>).