Functions

The following functions are available globally.

  • Add a constraint that requires that a key is greater than a value.

    Declaration

    Swift

    public func > <T>(key: String, value: T) -> QueryConstraint where T : Encodable

    Parameters

    key

    The key that the value is stored in.

    value

    The value to compare.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key is greater than or equal to a value.

    Declaration

    Swift

    public func >= <T>(key: String, value: T) -> QueryConstraint where T : Encodable

    Parameters

    key

    The key that the value is stored in.

    value

    The value to compare.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key is less than a value.

    Declaration

    Swift

    public func < <T>(key: String, value: T) -> QueryConstraint where T : Encodable

    Parameters

    key

    The key that the value is stored in.

    value

    The value to compare.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key is less than or equal to a value.

    Declaration

    Swift

    public func <= <T>(key: String, value: T) -> QueryConstraint where T : Encodable

    Parameters

    key

    The key that the value is stored in.

    value

    The value to compare.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key is equal to a value.

    Warning

    See equalTo for more information. Behavior changes based on ParseSwift.configuration.isUsingEqualQueryConstraint where isUsingEqualQueryConstraint == true is known not to work for LiveQuery on Parse Servers <= 5.0.0.

    Declaration

    Swift

    public func == <T>(key: String, value: T) -> QueryConstraint where T : Encodable

    Parameters

    key

    The key that the value is stored in.

    value

    The value to compare.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key is equal to a value.

    Warning

    usingEqComparator == true is known not to work for LiveQueries on Parse Servers <= 5.0.0.

    Declaration

    Swift

    public func equalTo <T>(key: String,
                            value: T,
                            //swiftlint:disable:next line_length
                            usingEqComparator: Bool = ParseSwift.configuration.isUsingEqualQueryConstraint) -> QueryConstraint where T: Encodable

    Parameters

    key

    The key that the value is stored in.

    value

    The value to compare.

    usingEqComparator

    Set to true to use $eq comparater, allowing for multiple QueryConstraint‘s to be used on a single key. Setting to false may override any QueryConstraint’s on the same key. Defaults to ParseSwift.configuration.isUsingEqualQueryConstraint.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key is equal to a ParseObject.

    Throws

    An error of type ParseError.

    Warning

    See equalTo for more information. Behavior changes based on ParseSwift.configuration.isUsingEqualQueryConstraint where isUsingEqualQueryConstraint == true is known not to work for LiveQuery on Parse Servers <= 5.0.0.

    Declaration

    Swift

    public func == <T>(key: String, value: T) throws -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key that the value is stored in.

    value

    The ParseObject to compare.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key is equal to a ParseObject.

    Throws

    An error of type ParseError.

    Warning

    usingEqComparator == true is known not to work for LiveQueries on Parse Servers <= 5.0.0.

    Declaration

    Swift

    public func equalTo <T>(key: String,
                            value: T,
                            //swiftlint:disable:next line_length
                            usingEqComparator: Bool = ParseSwift.configuration.isUsingEqualQueryConstraint) throws -> QueryConstraint where T: ParseObject

    Parameters

    key

    The key that the value is stored in.

    value

    The ParseObject to compare.

    usingEqComparator

    Set to true to use $eq comparater, allowing for multiple QueryConstraint‘s to be used on a single key. Setting to false may override any QueryConstraint’s on the same key. Defaults to ParseSwift.configuration.isUsingEqualQueryConstraint.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key is not equal to a value.

    Declaration

    Swift

    public func != <T>(key: String, value: T) -> QueryConstraint where T : Encodable

    Parameters

    key

    The key that the value is stored in.

    value

    The value to compare.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key is not equal to a ParseObject.

    Declaration

    Swift

    public func != <T>(key: String, value: T) throws -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key that the value is stored in.

    value

    The ParseObject to compare.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Returns a Query that is the or of the passed in queries.

    Declaration

    Swift

    public func or<T>(queries: [Query<T>]) -> QueryConstraint where T : ParseObject

    Parameters

    queries

    The list of queries to or together.

    Return Value

    An instance of QueryConstraint‘s that are the or of the passed in queries.

  • Returns a Query that is the or of the passed in queries.

    Declaration

    Swift

    public func or<T>(queries: Query<T>...) -> QueryConstraint where T : ParseObject

    Parameters

    queries

    The variadic amount of queries to or together.

    Return Value

    An instance of QueryConstraint‘s that are the or of the passed in queries.

  • Returns a Query that is the nor of the passed in queries.

    Declaration

    Swift

    public func nor<T>(queries: [Query<T>]) -> QueryConstraint where T : ParseObject

    Parameters

    queries

    The list of queries to nor together.

    Return Value

    An instance of QueryConstraint‘s that are the nor of the passed in queries.

  • Returns a Query that is the nor of the passed in queries.

    Declaration

    Swift

    public func nor<T>(queries: Query<T>...) -> QueryConstraint where T : ParseObject

    Parameters

    queries

    The variadic amount of queries to nor together.

    Return Value

    An instance of QueryConstraint‘s that are the nor of the passed in queries.

  • Constructs a Query that is the and of the passed in queries.

    For example:

    var compoundQueryConstraints = and([query1, query2, query3])
    

    will create a compoundQuery that is an and of the query1, query2, and query3.

    Declaration

    Swift

    public func and<T>(queries: [Query<T>]) -> QueryConstraint where T : ParseObject

    Parameters

    queries

    The list of queries to and together.

    Return Value

    An instance of QueryConstraint‘s that are the and of the passed in queries.

  • Constructs a Query that is the and of the passed in queries.

    For example:

    var compoundQueryConstraints = and(query1, query2, query3)
    

    will create a compoundQuery that is an and of the query1, query2, and query3.

    Declaration

    Swift

    public func and<T>(queries: Query<T>...) -> QueryConstraint where T : ParseObject

    Parameters

    queries

    The variadic amount of queries to and together.

    Return Value

    An instance of QueryConstraint‘s that are the and of the passed in queries.

  • Add a constraint that requires that a key’s value matches a Query constraint.

    Warning

    This only works where the key’s values are ParseObjects or arrays of ParseObjects.

    Declaration

    Swift

    public func == <T>(key: String, value: Query<T>) -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key that the value is stored in.

    query

    The query the value should match.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key’s value do not match a Query constraint.

    Warning

    This only works where the key’s values are ParseObjects or arrays of ParseObjects.

    Declaration

    Swift

    public func != <T>(key: String, query: Query<T>) -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key that the value is stored in.

    query

    The query the value should not match.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Adds a constraint that requires that a key’s value matches a value in another key in objects returned by a sub query.

    Declaration

    Swift

    public func matchesKeyInQuery<T>(key: String, queryKey: String, query: Query<T>) -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key that contains the value that is being matched.

    queryKey

    The key in objects in the returned by the sub query whose value should match.

    query

    The query to run.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Adds a constraint that requires that a key’s value not match a value in another key in objects returned by a sub query.

    Declaration

    Swift

    public func doesNotMatchKeyInQuery<T>(key: String, queryKey: String, query: Query<T>) -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key that contains the value that is being excluded.

    queryKey

    The key in objects returned by the sub query whose value should match.

    query

    The query to run.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s object to be contained in the provided array.

    Declaration

    Swift

    public func containedIn<T>(key: String, array: [T]) -> QueryConstraint where T : Encodable

    Parameters

    key

    The key to be constrained.

    array

    The possible values for the key’s object.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s object to be contained in the provided array of ParseObjects.

    Declaration

    Swift

    public func containedIn<T>(key: String, array: [T]) throws -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key to be constrained.

    array

    The possible values for the key’s object.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s object not be contained in the provided array.

    Declaration

    Swift

    public func notContainedIn<T>(key: String, array: [T]) -> QueryConstraint where T : Encodable

    Parameters

    key

    The key to be constrained.

    array

    The list of values the key’s object should not be.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s object not be contained in the provided array of ParseObject pointers.

    Declaration

    Swift

    public func notContainedIn<T>(key: String, array: [T]) throws -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key to be constrained.

    array

    The list of values the key’s object should not be.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s array contains every element of the provided array.

    Declaration

    Swift

    public func containsAll<T>(key: String, array: [T]) -> QueryConstraint where T : Encodable

    Parameters

    key

    The key to be constrained.

    array

    The possible values for the key’s object.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s array contains every element of the provided array of `ParseObject’s.

    Declaration

    Swift

    public func containsAll<T>(key: String, array: [T]) throws -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key to be constrained.

    array

    The possible values for the key’s object.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s object to be contained by the provided array. Get objects where all array elements match.

    Declaration

    Swift

    public func containedBy<T>(key: String, array: [T]) -> QueryConstraint where T : Encodable

    Parameters

    key

    The key to be constrained.

    array

    The possible values for the key’s object.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s object to be contained by the provided array of ParseObject‘s. Get objects where all array elements match.

    Declaration

    Swift

    public func containedBy<T>(key: String, array: [T]) throws -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key to be constrained.

    array

    The possible values for the key’s object.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s time is related to a specified time.

    For example:

    let queryRelative = GameScore.query(relative("createdAt" < "12 days ago"))
    

    will create a relative query where createdAt is less than 12 days ago.

    Warning

    Requires Parse Server 2.6.5+ for MongoDB and Parse Server 5.0.0+ for PostgreSQL.

    Declaration

    Swift

    public func relative(_ constraint: QueryConstraint) -> QueryConstraint

    Parameters

    constraint

    The key to be constrained. Should be a Date field. The value is a reference time, e.g. “12 days ago”. Currently only comparators supported are: <, <=, >, and >=.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s coordinates (specified via ParseGeoPoint) be near a reference point. Distance is calculated based on angular distance on a sphere. Results will be sorted by distance from reference point.

    Declaration

    Swift

    public func near(key: String, geoPoint: ParseGeoPoint) -> QueryConstraint

    Parameters

    key

    The key to be constrained.

    geoPoint

    The reference point represented as a ParseGeoPoint.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s coordinates (specified via ParseGeoPoint) be near a reference point and within the maximum distance specified (in radians). Distance is calculated based on angular distance on a sphere. Results will be sorted by distance (nearest to farthest) from the reference point.

    Declaration

    Swift

    public func withinRadians(key: String,
                              geoPoint: ParseGeoPoint,
                              distance: Double,
                              sorted: Bool = true) -> [QueryConstraint]

    Parameters

    key

    The key to be constrained.

    geoPoint

    The reference point as a ParseGeoPoint.

    distance

    Maximum distance in radians.

    sorted

    true if results should be sorted by distance ascending, false is no sorting is required. Defaults to true.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s coordinates (specified via ParseGeoPoint) be near a reference point and within the maximum distance specified (in miles). Distance is calculated based on a spherical coordinate system. Results will be sorted by distance (nearest to farthest) from the reference point.

    Declaration

    Swift

    public func withinMiles(key: String,
                            geoPoint: ParseGeoPoint,
                            distance: Double,
                            sorted: Bool = true) -> [QueryConstraint]

    Parameters

    key

    The key to be constrained.

    geoPoint

    The reference point represented as a ParseGeoPoint.

    distance

    Maximum distance in miles.

    sorted

    true if results should be sorted by distance ascending, false is no sorting is required. Defaults to true.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s coordinates (specified via ParseGeoPoint) be near a reference point and within the maximum distance specified (in kilometers). Distance is calculated based on a spherical coordinate system. Results will be sorted by distance (nearest to farthest) from the reference point.

    Declaration

    Swift

    public func withinKilometers(key: String,
                                 geoPoint: ParseGeoPoint,
                                 distance: Double,
                                 sorted: Bool = true) -> [QueryConstraint]

    Parameters

    key

    The key to be constrained.

    geoPoint

    The reference point represented as a ParseGeoPoint.

    distance

    Maximum distance in kilometers.

    sorted

    true if results should be sorted by distance ascending, false is no sorting is required. Defaults to true.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s coordinates (specified via ParseGeoPoint) be contained within a given rectangular geographic bounding box.

    Declaration

    Swift

    public func withinGeoBox(key: String, fromSouthWest southwest: ParseGeoPoint,
                             toNortheast northeast: ParseGeoPoint) -> QueryConstraint

    Parameters

    key

    The key to be constrained.

    fromSouthWest

    The lower-left inclusive corner of the box.

    toNortheast

    The upper-right inclusive corner of the box.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s coordinates be contained within and on the bounds of a given polygon Supports closed and open (last point is connected to first) paths.

    Polygon must have at least 3 points.

    Warning

    Requires Parse Server 2.5.0+.

    Declaration

    Swift

    public func withinPolygon(key: String, points: [ParseGeoPoint]) -> QueryConstraint

    Parameters

    key

    The key to be constrained.

    points

    The polygon points as an Array of ParseGeoPoint‘s.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s coordinates be contained within and on the bounds of a given polygon Supports closed and open (last point is connected to first) paths.

    Warning

    Requires Parse Server 2.5.0+.

    Declaration

    Swift

    public func withinPolygon(key: String, polygon: ParsePolygon) -> QueryConstraint

    Parameters

    key

    The key to be constrained.

    polygon

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint to the query that requires a particular key’s coordinates contains a ParseGeoPoint.

    Warning

    Requires Parse Server 2.6.0+.

    Declaration

    Swift

    public func polygonContains(key: String, point: ParseGeoPoint) -> QueryConstraint

    Parameters

    key

    The key of the ParsePolygon.

    point

    The ParseGeoPoint to check for containment.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint for finding string values that contain a provided string using Full Text Search.

    Note

    In order to sort you must use Query.sortByTextScore(). Your ParseObject should conform to ParseQueryScorable to retrieve the weight/rank via the “score” property of your ParseObject.

    Warning

    This may be slow for large datasets. Requires Parse Server > 2.5.0.

    Declaration

    Swift

    public func matchesText(key: String, text: String) -> QueryConstraint

    Parameters

    key

    The key to be constrained.

    text

    The substring that the value must contain.

    Return Value

    The resulting QueryConstraint.

  • Add a constraint for finding string values that contain a provided string using Full Text Search.

    Note

    In order to sort you must use Query.sortByTextScore(). Your ParseObject should conform to ParseQueryScorable to retrieve the weight/rank via the “score” property of your ParseObject.

    Warning

    This may be slow for large datasets. Requires Parse Server > 2.5.0.

    Declaration

    Swift

    public func matchesText(key: String,
                            text: String,
                            options: [ParseTextOption: Encodable]) throws -> QueryConstraint

    Parameters

    key

    The key to be constrained.

    text

    The substring that the value must contain.

    options

    The dictionary of options to constrain the search. The key is of type TextOption and must have a respective value.

    Return Value

    The resulting QueryConstraint.

  • Add a regular expression constraint for finding string values that match the provided regular expression.

    Warning

    This may be slow for large datasets.
    • i - Case insensitive search
    • m - Search across multiple lines of input

    Declaration

    Swift

    public func matchesRegex(key: String, regex: String, modifiers: String? = nil) -> QueryConstraint

    Parameters

    key

    The key that the string to match is stored in.

    regex

    The regular expression pattern to match.

    modifiers

    Any of the following supported PCRE modifiers (defaults to nil):

    Return Value

    The resulting QueryConstraint.

  • Add a constraint for finding string values that contain a provided substring.

    Warning

    This will be slow for large datasets.

    Declaration

    Swift

    public func containsString(key: String, substring: String, modifiers: String? = nil) -> QueryConstraint

    Parameters

    key

    The key that the string to match is stored in.

    substring

    The substring that the value must contain.

    modifiers

    Any of the following supported PCRE modifiers (defaults to nil):

    • i - Case insensitive search
    • m - Search across multiple lines of input

    Return Value

    The resulting QueryConstraint.

  • Add a constraint for finding string values that start with a provided prefix. This will use smart indexing, so it will be fast for large datasets.

    Declaration

    Swift

    public func hasPrefix(key: String, prefix: String, modifiers: String? = nil) -> QueryConstraint

    Parameters

    key

    The key that the string to match is stored in.

    prefix

    The substring that the value must start with.

    modifiers

    Any of the following supported PCRE modifiers (defaults to nil):

    • i - Case insensitive search
    • m - Search across multiple lines of input

    Return Value

    The resulting QueryConstraint.

  • Add a constraint for finding string values that end with a provided suffix.

    Warning

    This will be slow for large datasets.

    Declaration

    Swift

    public func hasSuffix(key: String, suffix: String, modifiers: String? = nil) -> QueryConstraint

    Parameters

    key

    The key that the string to match is stored in.

    suffix

    The substring that the value must end with.

    modifiers

    Any of the following supported PCRE modifiers (defaults to nil):

    • i - Case insensitive search
    • m - Search across multiple lines of input

    Return Value

    The resulting QueryConstraint.

  • Add a constraint that requires that a key is equal to null or undefined.

    Declaration

    Swift

    public func isNull(key: String) -> QueryConstraint

    Parameters

    key

    The key that the value is stored in.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires that a key is not equal to null or undefined.

    Declaration

    Swift

    public func isNotNull(key: String) -> QueryConstraint

    Parameters

    key

    The key that the value is stored in.

    Return Value

    The same instance of QueryConstraint as the receiver.

  • Add a constraint that requires a particular key to be equal to undefined.

    Declaration

    Swift

    public func exists(key: String) -> QueryConstraint

    Parameters

    key

    The key that should exist.

    Return Value

    The resulting QueryConstraint.

  • Add a constraint that requires a key to not be equal to undefined.

    Declaration

    Swift

    public func doesNotExist(key: String) -> QueryConstraint

    Parameters

    key

    The key that should not exist.

    Return Value

    The resulting QueryConstraint.

  • Add a constraint that requires a key is related.

    Throws

    An error of type ParseError.

    Declaration

    Swift

    public func related<T>(key: String, object: T) throws -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key that should be related.

    object

    The object that should be related.

    Return Value

    The resulting QueryConstraint.

  • Add a constraint that requires a key is related.

    Declaration

    Swift

    public func related<T>(key: String, object: Pointer<T>) -> QueryConstraint where T : ParseObject

    Parameters

    key

    The key that should be related.

    object

    The pointer object that should be related.

    Return Value

    The resulting QueryConstraint.

  • Add a constraint that requires a key is related.

    Throws

    An error of type ParseError.

    Declaration

    Swift

    public func related(key: String) -> QueryConstraint

    Parameters

    key

    The key that should be related.

    Return Value

    The resulting QueryConstraint.

  • Add a constraint that requires a key is related.

    Throws

    An error of type ParseError.

    Declaration

    Swift

    public func related<T>(object: T) throws -> QueryConstraint where T : ParseObject

    Parameters

    object

    The object that should be related.

    Return Value

    The resulting QueryConstraint.

  • Add a constraint that requires a key is related.

    Declaration

    Swift

    public func related<T>(object: Pointer<T>) -> QueryConstraint where T : ParseObject

    Parameters

    object

    The pointer object that should be related.

    Return Value

    The resulting QueryConstraint.