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.
-
init(selectingFieldsNamed:for:)Extension methodConvenience 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 instanceQueryOn<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. }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) throwsParameters
fieldNamesAn array of field names to include in the JSON response.
localeAn optional locale argument to return localized results. If unspecified, the locale originally set on the
Clientinstance is used. -
init(orderedUsing:)Extension methodConvenience 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...) throwsParameters
propertyNameOne or more properties on the Resource by which the results will be ordered.
reverseAn Bool specifying if the returned order should be reversed or not. Defaults to
false. -
init(limitingResultsTo:)Extension methodConvenience initializer for a limiting responses to a certain number of values. Use in conjunction with the
skipmethod 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) throwsParameters
numberOfResultsThe number of results the response will be limited to.
-
init(skippingTheFirst:)Extension methodConvenience initializer for a skipping the first
nitems in a response. Use in conjunction with thelimitmethod 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
numberOfResultsThe number of results that will be skipped in the query.
-
select(fieldsNamed:locale:)Extension methodInstance 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 instanceQueryOn<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. }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) throwsParameters
fieldNamesAn array of field names to include in the JSON response.
localeAn optional locale argument to return localized results. If unspecified, the locale originally set on the
Clientinstance is used. -
order(using:)Extension methodInstance 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...) throwsParameters
propertyNameOne or more properties on the Resource by which the results will be ordered.
reverseAn Bool specifying if the returned order should be reversed or not. Defaults to
false. -
limit(to:)Extension methodInstance method for further mutating a query to limit responses to a certain number of values. Use in conjunction with the
skipmethod 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) throwsParameters
numberOfResultsThe number of results the response will be limited to.
-
skip(theFirst:)Extension methodIntance method for further mutating a query to skip the first
nitems in a response. Use in conjunction with thelimitmethod 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
numberOfResultsThe number of results that will be skipped in the query.
-
init(searchingFor:for:)Extension methodConvenience initializer for querying entries or assets in which all text and symbol fields contain the specified, case-insensitive text parameter.
Declaration
Swift
public init(searchingFor text: String, for locale: String? = nil) throwsParameters
textThe text string to match against.
localeAn optional locale argument to return localized results. If unspecified, the locale originally set on the
Clientinstance is used. -
search(for:)Extension methodInstance method for appending a full-text search query to an existing query. Returned results will contain either entries or assets in which all text and symbol fields contain the specified, case-insensitive text parameter.
Declaration
Swift
public func search(for text: String)Parameters
textThe text string to match against.
localeAn optional locale argument to return localized results. If unspecified, the locale originally set on the
Clientinstance is used.
View on GitHub
ChainableQuery Protocol Reference