ChainableQuery

public protocol ChainableQuery : AbstractQuery

Protocol which enables concrete query implementations to be ‘chained’ together so that results can be filtered by more than one Query.Operation or other query. Protocol extensions give default implementation so that all concrete types, Query, AssetQuery, FilterQuery, and QueryOn<EntryType>, can use the same implementation.

KeyPath/Value operations.

  • where(sys:_:) Extension method

    Instance method for appending a Query.Operation to a Query. This variation for creating a query guarantees correct query construction when performing operations on “sys” members. See concrete types Query, FilterQuery, AssetQuery, and QueryOn for more information and example usage.

    Declaration

    Swift

    @discardableResult
    func `where`(sys key: Sys.CodingKeys, _ operation: Query.Operation) -> Self

    Parameters

    key

    The Sys.CodingKey of the system property you are performing the Query.Operation against. For instance, .id.

    operation

    The query operation used in the query.

    Return Value

    A reference to the receiving query to enable chaining.

  • where(metadata:_:) Extension method

    Instance method for appending a Query.Operation to a Query. This variation for creating a query guarantees correct query construction when performing operations on “metadata” members. See concrete types Query, FilterQuery, AssetQuery, and QueryOn for more information and example usage.

    Declaration

    Swift

    @discardableResult
    func `where`(metadata key: Metadata.CodingKeys, _ operation: Query.Operation) -> Self

    Parameters

    key

    The Metadata.CodingKey of the system property you are performing the Query.Operation against. For instance, .tags.

    operation

    The query operation used in the query.

    Return Value

    A reference to the receiving query to enable chaining.

  • where(metadataTagsIds:) Extension method

    Instance method for appending a Query.Operation to a Query. This variation for creating a query guarantees correct query construction when performing operations on “metadata” members. See concrete types Query, FilterQuery, AssetQuery, and QueryOn for more information and example usage.

    Declaration

    Swift

    @discardableResult
    func `where`(metadataTagsIds operation: Query.Operation) -> Self

    Parameters

    metadataTagsIds

    The query operation used in the query against metadata tags ids.

    Return Value

    A reference to the receiving query to enable chaining.

  • where(field:_:) Extension method

    Static method for creating a Query with a Query.Operation. This variation for creating a query guarantees correct query contruction when performing operations on “sys” members. See concrete types Query, FilterQuery, AssetQuery, and QueryOn for more information and example usage.

    Declaration

    Swift

    static func `where`(field fieldName: FieldName, _ operation: Query.Operation) -> Self

    Parameters

    fieldName

    The string name of the field that the Query.Operation is matching against. For instance, “.name”

    operation

    The query operation used in the query.

    Return Value

    A newly initialized query.

  • where(field:_:) Extension method

    Instance method for appending a Query.Operation to a Query. This variation for creating a query guarantees correct query contruction when performing operations on “field” members. See concrete types Query, FilterQuery, AssetQuery, and QueryOn for more information and example usage.

    Declaration

    Swift

    @discardableResult
    func `where`(field fieldName: FieldName, _ operation: Query.Operation) -> Self

    Parameters

    fieldName

    The string name of the field that the Query.Operation is matching against. For instance, “name”

    operation

    The query operation used in the query.

    Return Value

    A reference to the receiving query to enable chaining.

  • where(valueAtKeyPath:_:) Extension method

    Instance method for appending more Query.Operations to further filter results on the API. Example usage:

    let query = Query.where(contentTypeId: "cat").where("fields.color", .doesNotEqual("gray"))
    
    // Mutate the query further.
    query.where(valueAtKeyPath: "fields.lives", .equals("9"))
    

    Declaration

    Swift

    @discardableResult
    func `where`(valueAtKeyPath keyPath: String, _ operation: Query.Operation) -> Self

    Parameters

    keyPath

    The key path for the property you are performing the Query.Operation against. For instance, "sys.id" or“fields.yourFieldName”`.

    operation

    The query operation used in the query.

    Return Value

    A reference to the receiving query to enable chaining.

Full-text search

Response Manipulations.

  • include(_:) Extension method

    Static method for specifiying the level of includes to be resolved in the JSON response. The maximum permitted level of includes at the API level is 10; the SDK will limit the includes level at 10 before the network request is made if the passed in value is too high in order to avoid hitting an error from the API. To omit all linked items, specify an include level of 0.

    See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/links/retrieval-of-linked-items

    Declaration

    Swift

    static func include(_ includesLevel: UInt) -> Self

    Parameters

    includesLevel

    An unsigned integer specifying the level of includes to be resolved.

    Return Value

    A newly constructed query object specifying the level of includes to be linked.

  • include(_:) Extension method

    Specify the level of includes to be resolved in the JSON response. The maximum permitted level of includes at the API level is 10; the SDK will round down to the 10 before the network request is made if the passed in value is too high in order to avoid hitting an error from the API. To omit all linked items, specify an include level of 0.

    See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/links/retrieval-of-linked-items

    Declaration

    Swift

    @discardableResult
    func include(_ includesLevel: UInt) -> Self

    Parameters

    includesLevel

    An unsigned integer specifying the level of includes to be resolved.

    Return Value

    A reference to the receiving query to enable chaining.

  • skip(theFirst:) Extension method

    Static method for creating a query that specifies that the first n items in a collection should be skipped before returning the results. Use in conjunction with the limit(to:) and order(by:) methods to paginate responses.

    Example usage:

    let query = Query.skip(theFirst: 9)
    

    Declaration

    Swift

    static func skip(theFirst numberOfResults: UInt) -> Self

    Parameters

    numberOfResults

    The number of results that will be skipped in the query.

    Return Value

    A newly constructed query object specifying the number of items to skip.

  • skip(theFirst:) Extension method

    Instance method for further mutating a query to skip the first n items in a response. Use in conjunction with the limit(to:) and order(by:) methods to paginate responses.

    Example usage:

    let query = Query().skip(theFirst: 10)
    

    Declaration

    Swift

    @discardableResult
    func skip(theFirst numberOfResults: UInt) -> Self

    Parameters

    numberOfResults

    The number of results that will be skipped in the query.

    Return Value

    A reference to the receiving query to enable chaining.

  • order(by:) Extension method

    Convenience initializer for a ordering responses by the values at the specified field. Field types that can be specified are strings, numbers, or booleans.

    Example usage:

    let query = try! Query(orderBy: OrderParameter("sys.createdAt"))
    

    See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order and: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order-with-multiple-parameters

    Declaration

    Swift

    static func order(by order: Ordering...) -> Self

    Parameters

    order

    The specified Ordering.

    Return Value

    A newly constructed query object specifying the order of the results.

  • order(by:) Extension method

    Instance method for ordering responses by the values at the specified field. Field types that can be specified are strings, numbers, or booleans.

    Example usage:

    let query = try! Query().order(by: Ordering(sys: .createdAt))
    

    See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order and: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order-with-multiple-parameters

    Declaration

    Swift

    @discardableResult
    func order(by order: Ordering...) -> Self

    Parameters

    order

    The specified Ordering.

    Return Value

    A reference to the receiving query to enable chaining.

  • limit(to:) Extension method

    Static method for creating a query that limits responses to a certain number of values. Use in conjunction with the skip method to paginate responses. The maximum number of items that can be returned by the API on one page is 1000. The SDK will limit your value to 1000 if you pass in something larger in order to avoid getting an error returned from the delivery API.

    Example usage:

    let query = Query.limit(to: 10)
    

    Declaration

    Swift

    static func limit(to numberOfResults: UInt) -> Self

    Parameters

    numberOfResults

    The number of results the response will be limited to.

    Return Value

    A newly constructed query object specifying the number of resuls to be returned.

  • limit(to:) Extension method

    Instance method for further mutating a query to limit responses to a certain number of values. Use in conjunction with the skip method to paginate responses. The maximum number of items that can be returned by the API on one page is 1000. The SDK will truncate your value to 1000 if you pass in something larger in order to avoid getting an error returned from the delivery API. Use in conjunction with the skip(theFirst:) and order(by:) methods to paginate responses. Example usage:

    let query = try! Query().limit(to: 10)
    

    Declaration

    Swift

    @discardableResult
    func limit(to numberOfResults: UInt) -> Self

    Parameters

    numberOfResults

    The number of results the response will be limited to.

    Return Value

    A reference to the receiving query to enable chaining.