BaseQuery
public protocol BaseQuery : QueryProtocol, Queryable
A concrete implementation of BaseQuery which serves as the base class for Query
,
ContentTypeQuery
and AssetQuery
.
-
find(_:
Extension method) This is a generic find method which can be used to fetch collections of
ContentType
,Entry
, andAsset
instances.Example usage:
let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment) // To fetch Entry from specific contentType stack.contentType(uid: contentTypeUID).entry().query() .fetch { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with EntryModel array in items. case .failure(let error): //Error Message } } // To fetch allContentTypes stack.contentType().query() .find { (result: Result<ContentstackResponse<ContentTypeModel>, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with ContentTypeModel array in items. case .failure(let error): //Error Message } } // To fetch Assets stack.asset().query() .find { (result: Result<ContentstackResponse<AssetModel>, 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 find<ResourceType>(_ completion: @escaping ResultsHandler<ContentstackResponse<ResourceType>>) where ResourceType: Decodable & EndpointAccessible
Parameters
completion
A handler which will be called on completion of the operation.
-
where(valueAtKeyPath:
Extension method_: ) Method to adding Query.Operation to a Query/
Example usage:
let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment) // To fetch Entry from specific contentType stack.contentType(uid: contentTypeUID).entry().query() .where(valueAtKeyPath: "fieldUid", .equals("Field condition")) .fetch { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with EntryModel array in items. case .failure(let error): //Error Message } } // To fetch allContentTypes stack.contentType().query() .where(valueAtKeyPath: "fieldUid", .equals("Field condition")) .find { (result: Result<ContentstackResponse<ContentTypeModel>, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with ContentTypeModel array in items. case .failure(let error): //Error Message } } // To fetch Assets stack.asset().query() .where(valueAtKeyPath: "fieldUid", .equals("Field condition")) .find { (result: Result<ContentstackResponse<AssetModel>, 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`(valueAtKeyPath keyPath: String, _ operation: Query.Operation) -> Self
Parameters
keyPath
operation
The query operation used in the query.
-
skip(theFirst:
Extension method) Instance method to mutuating query to skip the first
n
records.// To fetch Entry from specific contentType stack.contentType(uid: contentTypeUID).entry().query() .skip(to: 20) .fetch { (result: Result
, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with EntryModel array in items. case .failure(let error): //Error Message } } // To fetch allContentTypes stack.contentType().query().skip(to: 20) .find { (result: Result , Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with ContentTypeModel array in items. case .failure(let error): //Error Message } } // To fetch Assets stack.asset().query().skip(to: 20) .find { (result: Result , 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 skip(theFirst numberOfResults: UInt) -> Self
Parameters
numberOfResults
The number of results that will be skipped in the query. Example usage: “` let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment)
-
limit(to:
Extension method) Instance method to mutuating query to limit response to contain
n
values.// To fetch Entry from specific contentType stack.contentType(uid: contentTypeUID).entry().query() .limit(to: 20) .fetch { (result: Result
, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with EntryModel array in items. case .failure(let error): //Error Message } } // To fetch allContentTypes stack.contentType().query().limit(to: 20) .find { (result: Result , Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with ContentTypeModel array in items. case .failure(let error): //Error Message } } // To fetch Assets stack.asset().query().limit(to: 20) .find { (result: Result , 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 limit(to numberOfResults: UInt) -> Self
Parameters
numberOfResults
The number of results the response will be limited to. Example usage: “` let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment)
-
orderByAscending(keyPath:
Extension method) Instance method to ordering the response in ascending for specific field.
// To fetch Entry from specific contentType stack.contentType(uid: contentTypeUID).entry().query() .orderByAscending(keyPath: “fieldUID”) .fetch { (result: Result
, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with EntryModel array in items. case .failure(let error): //Error Message } } // To fetch allContentTypes stack.contentType().query().orderByAscending(keyPath: “fieldUID”) .find { (result: Result , Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with ContentTypeModel array in items. case .failure(let error): //Error Message } } // To fetch Assets stack.asset().query().orderByAscending(keyPath: “fieldUID”) .find { (result: Result , 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(keyPath: String) -> Self
Parameters
keyPath
The key path for the property you are performing ordering. Example usage: “` let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment)
-
orderByDecending(keyPath:
Extension method) Instance method to ordering the response in descending for specific field.
// To fetch Entry from specific contentType stack.contentType(uid: contentTypeUID).entry().query() .orderByDecending(keyPath: “fieldUID”) .fetch { (result: Result
, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with EntryModel array in items. case .failure(let error): //Error Message } } // To fetch allContentTypes stack.contentType().query().orderByDecending(keyPath: “fieldUID”) .find { (result: Result , Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with ContentTypeModel array in items. case .failure(let error): //Error Message } } // To fetch Assets stack.asset().query().orderByDecending(keyPath: “fieldUID”) .find { (result: Result , 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(keyPath: String) -> Self
Parameters
keyPath
The key path for the property you are performing ordering. Example usage: “` let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment)
-
addURIParam(dictionary:
Extension method) The parameters dictionary that are converted to
URLComponents
.Example usage:
let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment) // To fetch Entry from specific contentType stack.contentType(uid: contentTypeUID).entry().query() .addURIParam(dictionary: ["key": "value"]) .fetch { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with EntryModel array in items. case .failure(let error): //Error Message } } // To fetch allContentTypes stack.contentType().query().addURIParam(dictionary: ["key": "value"]) .find { (result: Result<ContentstackResponse<ContentTypeModel>, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with ContentTypeModel array in items. case .failure(let error): //Error Message } } // To fetch Assets stack.asset().query().addURIParam(dictionary: ["key": "value"]) .find { (result: Result<ContentstackResponse<AssetModel>, 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 addURIParam(dictionary: [String : String]) -> Self
Parameters
dictionary
The dictionary for URLComponents.
-
addURIParam(with:
Extension methodvalue: ) The parameters dictionary that are converted to
URLComponents
.// To fetch Entry from specific contentType stack.contentType(uid: contentTypeUID).entry().query() .addURIParam(with: “key”, value: “value”) .fetch { (result: Result
, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with EntryModel array in items. case .failure(let error): //Error Message } } // To fetch allContentTypes stack.contentType().query().addURIParam(with: “key”, value: “value”) .find { (result: Result , Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with ContentTypeModel array in items. case .failure(let error): //Error Message } } // To fetch Assets stack.asset().query().addURIParam(with: “key”, value: “value”) .find { (result: Result , 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 addURIParam(with key: String, value: String) -> Self
Parameters
key
The key for query parameter,
value
The value for query parameter. “` let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment)
-
addQuery(dictionary:
Extension method) The Query parameters dictionary that are converted to
URLComponents
.Example usage:
let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment) // To fetch Entry from specific contentType stack.contentType(uid: contentTypeUID).entry().query() .addQuery(dictionary: ["key": "value"]) .fetch { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with EntryModel array in items. case .failure(let error): //Error Message } } // To fetch allContentTypes stack.contentType().query().addQuery(dictionary: ["key": "value"]) .find { (result: Result<ContentstackResponse<ContentTypeModel>, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with ContentTypeModel array in items. case .failure(let error): //Error Message } } // To fetch Assets stack.asset().query().addQuery(dictionary: ["key": "value"]) .find { (result: Result<ContentstackResponse<AssetModel>, 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 addQuery(dictionary: [String : Any]) -> Self
Parameters
dictionary
The dictionary for URLComponents
-
addQuery(with:
Extension methodvalue: ) The Query parameters dictionary that are converted to
URLComponents
.Example usage:
let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment) // To fetch Entry from specific contentType stack.contentType(uid: contentTypeUID).entry().query() .addQuery(with: "key", value: "value") .fetch { (result: Result<ContentstackResponse<EntryModel>, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with EntryModel array in items. case .failure(let error): //Error Message } } // To fetch allContentTypes stack.contentType().query().addQuery(with: "key", value: "value") .find { (result: Result<ContentstackResponse<ContentTypeModel>, Error>, response: ResponseType) in switch result { case .success(let contentstackResponse): // Contentstack response with ContentTypeModel array in items. case .failure(let error): //Error Message } } // To fetch Assets stack.asset().query().addQuery(with: "key", value: "value") .find { (result: Result<ContentstackResponse<AssetModel>, 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 addQuery(with key: String, value: Any) -> Self
Parameters
key
The key for query parameter,
value
The value for query parameter.