ContentType
public class ContentType : CachePolicyAccessible
extension ContentType: ResourceQueryable
Content type defines the structure or schema of a page or a section of your web or mobile property. Read more about Content Types.
-
Declaration
Swift
public var cachePolicy: CachePolicy
-
Get instance of
Entry
to fetchEntry
or fetch specificEntry
.Example usage:
let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment) // To perform `Entry` query: let query = stack.Entry().query() // To get specific `Entry` instance from uid: let entry = stack.Entry(uid: entryUid)
Declaration
Swift
public func entry(uid: String? = nil) -> Entry
Parameters
uid
The UId of
Entry
you want to fetch data,Return Value
Entry
instance -
To include Global Fields schema in ContentType response.
Example usage:
let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment) stack.contentType().query().includeGlobalFields() .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 } }
Declaration
Swift
public func includeGlobalFields() -> ContentType
Return Value
A
ContentType
to enable chaining. -
To fetch all or find ContentTypes
query
method is used.Example usage:
let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment) 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 } }
Declaration
Swift
public func query() -> ContentTypeQuery
Return Value
A
ContentTypeQuery
to enable chaining. -
This call fetches the latest version of a specific
ContentType
of a particular stack.Example usage:
let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment) stack.contentType(uid: assetUID) .fetch { (result: Result<ContentTypeModel, Error>, response: ResponseType) in switch result { case .success(let model): //Model retrive from API case .failure(let error): //Error Message } }
Declaration
Swift
public func fetch<ResourceType>(_ completion: @escaping (Result<ResourceType, Error>, ResponseType) -> Void) where ResourceType: EndpointAccessible, ResourceType: Decodable
Parameters
completion
A handler which will be called on completion of the operation.