Stack

public class Stack : CachePolicyAccessible

Stack is instance for performing Contentstack Delivery API request.

  • API Key is a unique key assigned to each stack.

    Declaration

    Swift

    public let apiKey: String
  • Delivery Token is a read-only credential that you can create for different environments of your stack.

    Declaration

    Swift

    public let deliveryToken: String
  • Environment can be defined as one or more content delivery destinations

    Declaration

    Swift

    public let environment: String
  • The domain host to perform requests against. Defaults to Host.delivery i.e. "cdn.contentstack.com".

    Declaration

    Swift

    public let host: String
  • Region refers to the location of the data centers where your organization’s data resides.

    Declaration

    Swift

    public let region: ContentstackRegion
  • Stack api version point

    Declaration

    Swift

    public let apiVersion: String
  • Branch is a

    Declaration

    Swift

    public let branch: String?
  • CachePolicy allows you to cache request

    Declaration

    Swift

    public var cachePolicy: CachePolicy
  • The JSONDecoder that the receiving client instance uses to deserialize JSON. The SDK will inject information about the locales to this decoder and use this information to normalize the fields dictionary of entries and assets.

    Declaration

    Swift

    public private(set) var jsonDecoder: JSONDecoder { get }
  • Get instance of ContentType to fetch content-types and schema or fetch entries of specific content-type.

    Example usage: let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment)

     // To perform `ContentType` query:
     let query = stack.contentType().query()
     // To fetch specific `ContentType` entries:
     let entry = stack.contentType(uid: contentTypeUid).entry()
    

    Declaration

    Swift

    public func contentType(uid: String? = nil) -> ContentType

    Parameters

    uid

    The UId of ContentType you want to fetch data,

    Return Value

    ContentType instance

  • Get instance of Asset to fetch Assets or fetch specific Asset.

    Example usage: let stack = Contentstack.stack(apiKey: apiKey, deliveryToken: deliveryToken, environment: environment)

     // To perform `Asset` query:
     let query = stack.asset().query()
     // To get specific `Asset` instance from uid:
     let asset = stack.asset(uid: assetUid)
    

    Declaration

    Swift

    public func asset(uid: String? = nil) -> Asset

    Parameters

    uid

    The UId of Asset you want to fetch data,

    Return Value

    Asset instance

  • The Initial Sync request performs a complete sync of your app data. It returns all the published entries and assets of the specified stack in response. The response also contains a sync_token, which you get in SyncStack, since this token is used to get subsequent delta updates later.

    Example usage:

     let stack = Contentstack.stack(apiKey: apiKey,
                 deliveryToken: deliveryToken,
                 environment: environment)
    
     stack.sync { (result: Result<SyncStack, Error>) in
        switch result {
        case .success(let syncStack):
             let items = syncStack.items
        case .failure(let error):
             print(error)
        }
     }
    

    Declaration

    Swift

    public func sync(_ syncStack: SyncStack = SyncStack(),
                     syncTypes: [SyncStack.SyncableTypes] = [.all],
                     then completion: @escaping (_ result: Result<SyncStack, Error>) -> Void)

    Parameters

    syncStack

    The relevant SyncStack to perform the subsequent sync on. Defaults to a new empty instance of SyncStack.

    syncTypes

    SyncableTypes that can be sync.

    completion

    A handler which will be called on completion of the operation.