Query

public class Query : BaseQuery, EntryQueryable

To fetch all or find Entries use Query.

  • Undocumented

    Declaration

    Swift

    public typealias ResourceType = EntryModel
  • Stack instance for Entry to be fetched

    Declaration

    Swift

    public var stack: Stack
  • URI Parameters

    Declaration

    Swift

    public var parameters: [String : Any]
  • Query Parameters

    Declaration

    Swift

    public var queryParameter: [String : Any]
  • Declaration

    Swift

    public var cachePolicy: CachePolicy
  • Use this method to do a search on Entries which enables searching for entries based on value’s for field key Path.

    Example usage:

    let stack = Contentstack.stack(apiKey: apiKey,
                deliveryToken: deliveryToken,
                environment: environment)
    
    stack.contentType(uid: contentTypeUid).entry().query()
    .where(valueAtKey: .title, .equals("Entry Title"))
    .find { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in
        switch result {
        case .success(let contentstackResponse):
            // Contentstack response with AssetModel array in items.
        case .failure(let error):
            //Error Message
        }
    }
    

    Declaration

    Swift

    public func `where`(valueAtKey path: String, _ operation: Query.Operation) -> Query

    Parameters

    path

    The field key path that you are performing your select operation against.

    operation

    The query operation used in the query.

    Return Value

    A Query to enable chaining.

  • Use this method to do a search on Entries which enables searching for entries based on value’s queryable coding from EntryModel.FieldKeys.

    Example usage:

    let stack = Contentstack.stack(apiKey: apiKey,
                deliveryToken: deliveryToken,
                environment: environment)
    
    stack.contentType(uid: contentTypeUid).entry().query()
    .where(queryableCodingKey: .title, .equals("Entry Title"))
    .find { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in
        switch result {
        case .success(let contentstackResponse):
            // Contentstack response with AssetModel array in items.
        case .failure(let error):
            //Error Message
        }
    }
    

    Declaration

    Swift

    public func `where`(queryableCodingKey: EntryModel.FieldKeys, _ operation: Query.Operation) -> Query

    Parameters

    queryableCodingKey

    The member of your EntryModel.FieldKeys that you are performing your select operation against.

    operation

    The query operation used in the query.

    Return Value

    A Query to enable chaining.

  • Use this method to do a search on Entries which enables searching for entries based on value’s for members of referenced entries.

    Example usage:

    let stack = Contentstack.stack(apiKey: apiKey,
                deliveryToken: deliveryToken,
                environment: environment)
    
    stack.contentType(uid: contentTypeUid).entry().query()
    .where(referenceAtKeyPath: .title, .equals("Entry Title"))
    .find { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in
        switch result {
        case .success(let contentstackResponse):
            // Contentstack response with AssetModel array in items.
        case .failure(let error):
            //Error Message
        }
    }
    

    Declaration

    Swift

    public func `where`(referenceAtKeyPath keyPath: String, _ operation: Query.Reference) -> Query

    Parameters

    keyPath

    The reference field key path that you are performing your select operation against.

    operation

    The query operation used in the query.

    Return Value

    A Query to enable chaining.

  • When fetching entries, you can sort them in the ascending order with respect to the value of a specific field in the response body.

    Example usage:

    let stack = Contentstack.stack(apiKey: apiKey,
                deliveryToken: deliveryToken,
                environment: environment)
    
    stack.contentType(uid: contentTypeUid).entry().query()
    .orderByAscending(propertyName: .title)
    .find { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in
        switch result {
        case .success(let contentstackResponse):
            // Contentstack response with AssetModel array in items.
        case .failure(let error):
            //Error Message
        }
    }
    

    Declaration

    Swift

    @discardableResult
    public func orderByAscending(propertyName: EntryModel.FieldKeys) -> Query

    Parameters

    propertyName

    The member of your EntryModel.FieldKeys that you are performing order by ascending.

    Return Value

    A Query to enable chaining.

  • When fetching entries, you can sort them in the decending order with respect to the value of a specific field in the response body.

    Example usage:

    let stack = Contentstack.stack(apiKey: apiKey,
                deliveryToken: deliveryToken,
                environment: environment)
    
    stack.contentType(uid: contentTypeUid).entry().query()
    .orderByDecending(propertyName: .title)
    .find { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in
        switch result {
        case .success(let contentstackResponse):
            // Contentstack response with AssetModel array in items.
        case .failure(let error):
            //Error Message
        }
    }
    

    Declaration

    Swift

    @discardableResult
    public func orderByDecending(propertyName: EntryModel.FieldKeys) -> Query

    Parameters

    propertyName

    The member of your EntryModel.FieldKeys that you are performing order by decending.

    Return Value

    A Query to enable chaining.

  • Use this method to do a search on Entries.

    Example usage:

    let stack = Contentstack.stack(apiKey: apiKey,
                deliveryToken: deliveryToken,
                environment: environment)
    
    stack.contentType(uid: contentTypeUid).entry().query()
    .search(for: "searchString")
    .find { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in
        switch result {
        case .success(let contentstackResponse):
            // Contentstack response with AssetModel array in items.
        case .failure(let error):
            //Error Message
        }
    }
    

    Declaration

    Swift

    @discardableResult
    public func search(for text: String) -> Query

    Parameters

    text

    The text string to match against.

    Return Value

    A Query to enable chaining.

  • Use this method to do a search on tags for Entries.

    Example usage:

    let stack = Contentstack.stack(apiKey: apiKey,
                deliveryToken: deliveryToken,
                environment: environment)
    
    stack.contentType(uid: contentTypeUid).entry().query()
    .tags(for: "tagSearchString")
    .find { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in
        switch result {
        case .success(let contentstackResponse):
            // Contentstack response with AssetModel array in items.
        case .failure(let error):
            //Error Message
        }
    }
    

    Declaration

    Swift

    @discardableResult
    public func tags(for text: String) -> Query

    Parameters

    text

    The text string to match against.

    Return Value

    A Query to enable chaining.

  • Use this method to do a search on Entries which enables searching for entries based on Query.Operator.

    Example usage:

    let stack = Contentstack.stack(apiKey: apiKey,
                deliveryToken: deliveryToken,
                environment: environment)
    
    stack.contentType(uid: contentTypeUid).entry().query()
    .tags(for: "tagSearchString")
    .find { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in
        switch result {
        case .success(let contentstackResponse):
            // Contentstack response with AssetModel array in items.
        case .failure(let error):
            //Error Message
        }
    }
    

    Declaration

    Swift

    public func `operator`(_ operator: Query.Operator) -> Query

    Parameters

    operator

    The member of Query.Operator that you are performing

    Return Value

    A Query to enable chaining.

  • When fetching entries, you can perform and or or operation.

    See more

    Declaration

    Swift

    public enum Operator
  • When fetching entries, you can search base on reference $in or $nin.

    See more

    Declaration

    Swift

    public enum Reference
  • When fetching entries, you can search on field key paths.

    See more

    Declaration

    Swift

    public enum Operation
  • The Query.Include is parameter for including count, Unpublished, ContentType schema, Global Fields schema, and Reference ContentType Uid in result.

    See more

    Declaration

    Swift

    public struct Include : OptionSet