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 QueryOperation or other query. Protocol extensions give default implementation so that all concrete types, Query, AssetQuery, FilterQuery, and QueryOn<EntryType>, can use the same implementation.

  • Convenience initializer for a select operation query in which only the fields specified in the fieldNames property will be returned in the JSON response. The "sys" dictionary is always requested by the SDK. Note that if you are using the select operator with an instance QueryOn<EntryType> that you must make properties that you are ommitting in the response (by not including them in your selections array) optional properties. Example usage:

    let query = try! QueryOn<Cat>(selectingFieldsNamed: ["fields.bestFriend", "fields.color", "fields.name"])
    client.fetchMappedEntries(with: query).observable.then { catsResponse in
       let cats = catsResponse.items
       // Do stuff with cats.
    }
    

    See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/select-operator

    Throws

    Will throw an error if property names are not prefixed with "fields.", if selections go more than 2 levels deep (fields.bestFriend.sys is not valid), or if more than 99 properties are selected.

    Declaration

    Swift

    public init(selectingFieldsNamed fieldNames: [String], for locale: String? = nil) throws

    Parameters

    fieldNames

    An array of field names to include in the JSON response.

    locale

    An optional locale argument to return localized results. If unspecified, the locale originally set on the Client instance is used.

  • init(orderedUsing:) 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(orderedUsing: OrderParameter("sys.createdAt"))
    
    client.fetchEntries(with: query).observable.then { entriesResponse in
       let entries = entriesResponse.items
       // Do stuff with entries.
    }
    

    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

    Throws

    Will throw an error if property names are not prefixed with either "sys." or "fields.".

    Declaration

    Swift

    public init(orderedUsing orderParameters: OrderParameter...) throws

    Parameters

    propertyName

    One or more properties on the Resource by which the results will be ordered.

    reverse

    An Bool specifying if the returned order should be reversed or not. Defaults to false.

  • init(limitingResultsTo:) Extension method

    Convenience initializer for a limiting responses to a certain number of values. Use in conjunction with the skip method to paginate responses.

    Example usage:

    let query = try! Query(orderedBy: "sys.createdAt")
    
    client.fetchEntries(with: query).observable.then { entriesResponse in
       let entries = entriesResponse.items
       // Do stuff with entries.
    }
    

    Declaration

    Swift

    public init(limitingResultsTo numberOfResults: UInt) throws

    Parameters

    numberOfResults

    The number of results the response will be limited to.

  • init(skippingTheFirst:) Extension method

    Convenience initializer for a skipping the first n items in a response. Use in conjunction with the limit method to paginate responses.

    Example usage:

    let query = try! Query(skippingTheFirst: 9)
    
    client.fetchEntries(with: query).observable.then { entriesResponse in
       let entries = entriesResponse.items
       // Do stuff with entries.
    }
    

    Declaration

    Swift

    public init(skippingTheFirst numberOfResults: UInt)

    Parameters

    numberOfResults

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

  • select(fieldsNamed:locale:) Extension method

    Instance method for select operation in which only the fields specified in the fieldNames property will be returned in the JSON response. The "sys" dictionary is always requested by the SDK. Note that if you are using the select operator with an instance QueryOn<EntryType> that you must make properties that you are ommitting in the response (by not including them in your selections array) optional properties. Example usage:

    let query = try! QueryOn<Cat>()
    query.select(fieldsNamed: ["fields.bestFriend", "fields.color", "fields.name"])
    client.fetchEntries(with: query).observable.then { catsResponse in
       let cats = catsResponse.items
       // Do stuff with cats.
    }
    

    See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/select-operator

    Throws

    Will throw an error if property names are not prefixed with "fields.", if selections go more than 2 levels deep (fields.bestFriend.sys is not valid), or if more than 99 properties are selected.

    Declaration

    Swift

    func select(fieldsNamed fieldNames: [String], locale: String? = nil) throws

    Parameters

    fieldNames

    An array of field names to include in the JSON response.

    locale

    An optional locale argument to return localized results. If unspecified, the locale originally set on the Client instance is used.

  • order(using:) 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(orderedUsing: OrderParameter("sys.createdAt"))
    
    client.fetchEntries(with: query).observable.then { entriesResponse in
       let entries = entriesResponse.items
       // Do stuff with entries.
    }
    

    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

    Throws

    Will throw an error if property names are not prefixed with either "sys." or "fields.".

    Declaration

    Swift

    public func order(using orderParameters: OrderParameter...) throws

    Parameters

    propertyName

    One or more properties on the Resource by which the results will be ordered.

    reverse

    An Bool specifying if the returned order should be reversed or not. Defaults to false.

  • 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.

    Example usage:

    let query = try! Query(orderedBy: "sys.createdAt")
    
    client.fetchEntries(with: query).observable.then { entriesResponse in
       let entries = entriesResponse.items
       // Do stuff with entries.
    }
    

    Declaration

    Swift

    public func limit(to numberOfResults: UInt) throws

    Parameters

    numberOfResults

    The number of results the response will be limited to.

  • skip(theFirst:) Extension method

    Intance method for further mutating a query to skip the first n items in a response. Use in conjunction with the limit method to paginate responses.

    Example usage:

    let query = try! Query(skippingTheFirst: 9)
    
    client.fetchEntries(with: query).observable.then { entriesResponse in
       let entries = entriesResponse.items
       // Do stuff with entries.
    }
    

    Declaration

    Swift

    public func skip(theFirst numberOfResults: UInt)

    Parameters

    numberOfResults

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