AssetQuery

public final class AssetQuery : ResourceQuery

Queries on Asset types. All methods from ChainableQuery are available.

  • Convenience initializer for creating an AssetQuery with the “mimetype_group” parameter specified. Example usage:

    let query = AssetQuery.where(mimetypeGroup: .image)
    

    Declaration

    Swift

    public static func `where`(mimetypeGroup: MimetypeGroup) -> AssetQuery

    Parameters

    mimetypeGroup

    The mimetype_group which all returned Assets will match.

    Return Value

    A newly initialized AssetQuery query.

  • Instance method for mutating the query further to specify the mimetype group when querying assets.

    Declaration

    Swift

    @discardableResult
    public func `where`(mimetypeGroup: MimetypeGroup) -> AssetQuery

    Parameters

    mimetypeGroup

    The mimetype_group which all returned Assets will match.

    Return Value

    A reference to the receiving query to enable chaining.

  • Static method for creating a new AssetQuery with a select operation: an operation in which only the fields specified in the fieldNames parameter will be returned in the JSON response. This variation for initialization guarantees correct query contruction by utilizing the typesafe Asset.FieldKeys. The “sys” dictionary is always requested by the SDK.

    Example usage:

    let query = AssetQuery.select(fieldsNamed: [.file])
    client.fetchArray(of: Asset.self, matching: query) { (result: Result<ArrayResponse<Asset>>) in
        switch result {
        case .success(let arrayResponse):
            let assets = arrayResponse.items
            // Do stuff with assets.
        case .failure(let error):
            print(error)
        }
    }
    

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

    Declaration

    Swift

    public static func select(fields fieldsKeys: [Asset.Fields]) -> AssetQuery

    Parameters

    fieldsKeys

    An array of Asset.FieldKeys of the asset you are performing your select operation against.

    Return Value

    A newly initialized AssetQuery query.

  • Instance method for mutating an AssetQuery with a select operation: an operation in which only the fields specified in the fieldNames parameter will be returned in the JSON response. This variation for initialization guarantees correct query contruction by utilizing the typesafe Asset.FieldKeys. The “sys” dictionary is always requested by the SDK.

    let query = AssetQuery.select(fieldsNamed: [.file])
    client.fetchMappedEntries(with: query).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

    Declaration

    Swift

    @discardableResult
    public func select(fields fieldsKeys: [Asset.Fields]) -> AssetQuery

    Parameters

    fieldsKeys

    An array of Asset.FieldKeys of the asset you are performing your select operation against.

    Return Value

    A reference to the receiving query to enable chaining.