Stack

View as Markdown

Stack

Initialize an instance of ‘Stack’

NameTypeDescription
apiKey (required)NSString

Readonly property for Stack API Key

accessToken (required)NSString

Readonly property for Stack of access token/delivery token specific to environment

environment (required)NSString

Read only property of Stack environment to get content.

config Config

Read only property of Stack configuration.

contentTypeWithName:

Gets the new instance of ContentType object with specified name.

NameTypeDescription
contentTypeName (required)NSString

Uid of the contentType to perform action.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


ContentType *contentTypeObj = [stack contentTypeWithName:@"CONTENT_TYPE_UID"];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


var contentTypeObj:ContentType = stack.contentTypeWithName("CONTENT_TYPE_UID")

setHeader:forKey:

Set a header for Stack.

NameTypeDescription
headerValue (required)NSString

The header value

headerKey (required)NSString

The header key

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


[stack setHeader:@"MyValue" forKey:@"My-Custom-Header"];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


stack.setHeader("MyValue", forKey: "My-Custom-Header")

addHeadersWithDictionary:

Set a header for Stack

NameTypeDescription
headers (required)NSDictionary<NSString*,NSString*>

The headers as dictionary which needs to be added to the application.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


[stack addHeadersWithDictionary:@{@"My-Custom-Header": @"MyValue"}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


stack.addHeadersWithDictionary(["My-Custom-Header":"MyValue"])

removeHeaderForKey:

Removes a header from this Stack.

NameTypeDescription
headerKey (required)NSString

The header key that needs to be removed.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


[stack removeHeaderForKey:@"key"];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


stack.removeHeaderForKey("key")

assetLibrary

Represents a Asset on ‘Stack’ which can be executed to get AssetLibrary object.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];


AssetLibrary *asset = [stack assetLibrary];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


var asset:AssetLibrary = stack.assetLibrary()

asset

Represents an Asset on ‘Stack’ which can be executed to get Asset object.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];


Asset *asset = [stack asset];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


var asset:Asset = stack.asset()

assetWithUID:

Gets the new instance of Asset object with specified UID.

NameTypeDescription
uid (required)NSString

Uid of the Asset object to fetch.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


[[stack sync:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


stack.sync({ ( syncStack:SyncStack, error: NSError) in


})

imageTransformWithUrl:andParams:

Transforms provided image url based on transformation parameters.

NameTypeDescription
url (required)NSString

Url on which transformations to be applied.

params (required)NSDictionary<NSString*,id>

Transformation parameters.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];

NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:100], @"width", [NSNumber numberWithInt:100], @"height", nil];

NSString *transformedUrl = [stack imageTransformWithUrl:imageURL andParams:params];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")

let params:[String : AnyObject?] = [

  "width":100 as AnyObject,

  "height":100 as AnyObject,

];

let transformedUrl:String = stack.imageTransformation(withUrl: imageURL, andParams: params);

getContentTypes:completion:

Gets all the ContentTypes and its Schema definition.

NameTypeDescription
params (required)NSDictionary<NSString*,id>

params is dictionary of additional parameter

completionBlock (required)(NSArray<NSString*> *BUILT_NULLABLE_P contentTypes , NSError *BUILT_NULLABLE_P error)

completionBlock to be called once operation is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


[stack getContentTypes:params completion:^(NSArray * _Nullable contentTypes, NSError * _Nullable error) {


 }];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


stack.getContentTypes(params, { (contentTypes, error) in


})

sync:

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 need to store, since this token is used to get subsequent delta updates later.

NameTypeDescription
completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


[[stack sync:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


stack.sync({ ( syncStack:SyncStack, error: NSError) in


})

syncPaginationToken:completion:

If the result of the initial sync (or subsequent sync) contains more than 100 records, the response would be paginated. It provides pagination token in the response. However, you do not have to use the pagination token manually to get the next batch, the SDK does that automatically until the sync is complete. Pagination token can be used in case you want to fetch only selected batches. It is especially useful if the sync process is interrupted midway (due to network issues, etc.). In such cases, this token can be used to restart the sync process from where it was interrupted.

NameTypeDescription
token (required)NSString

Pagination token from where to perform sync

completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


[stack syncPaginationToken:@"PAGINATION_TOKEN" contentTypeArray completion:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


stack.syncPaginationToken("PAGINATION_TOKEN", completion: { ( syncStack:SyncStack, error: NSError) in


})

syncToken:completion:

You can use the sync token (that you receive after initial sync) to get the updated content next time. The sync token fetches only the content that was added after your last sync, and the details of the content that was deleted or updated.

NameTypeDescription
token (required)NSString

Sync token from where to perform sync

completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


[[stack syncToken:@"SYNC_TOKEN" contentTypeArray completion:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


stack.syncToken("SYNC_TOKEN", completion: { ( syncStack:SyncStack, error: NSError) in


})

syncOnly:completion:

Perform a synchronization operation on specified classes.

NameTypeDescription
contentType (required)NSString

ContentType uids of classes to be expected.

completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];</span>


NSArray *contentTypeArray = @[@“product”, @“multifield”]; 

[[stack syncOnly: contentTypeArray completion:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


let contentTypeArray = [“product”, “multifield”]

stack.syncOnly(contentTypeArray, completion: { ( syncStack:SyncStack, error: NSError) in


})

syncFrom:completion:

Perform a synchronization operation on specified date.

NameTypeDescription
date (required)NSDate

Date from where sync data is needed.

completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


NSDate *date = [NSDate date]; 

[[stack syncFrom:date completion:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


let date = Date.date() 

stack.syncFrom(date, completion: { ( syncStack:SyncStack, error: NSError) in


})

syncOnly:from:completion:

Perform a synchronization operation on specified classes, and date.

NameTypeDescription
contentType (required)NSString

ContentType uids of classes to be expected.

date (required)NSDate

Date from where sync data is needed.

completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];</span>


NSArray *contentTypeArray = @[@“product”, @“multifield”]; 

[[stack syncOnly: contentTypeArray from:date completion:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


let contentTypeArray = [“product”, “multifield”]

stack.syncOnly(contentTypeArray, from: date, completion: { ( syncStack:SyncStack, error: NSError) in


})

syncPublishType:completion:

Perform a synchronization operation on specified publishType.

NameTypeDescription
publishType (required)PublishType

PublishType for which sync is needed.

completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];</span>


[[stack syncPublishType:ENTRY_PUBLISHED completion:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


stack.syncPublishType(ENTRY_PUBLISHED, completion: { ( syncStack:SyncStack, error: NSError) in


})

syncLocale:completion:

Perform a synchronization operation on specified locale.

NameTypeDescription
locale (required)NSString

Locale for which sync is needed.

completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];</span>


[[stack syncLocale:ENGLISH_UNITED_STATES completion:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


stack.syncLocale(locale:ENGLISH_UNITED_STATES, completion: { ( syncStack:SyncStack, error: NSError) in


})

syncLocale:from:completion:

Perform a synchronization operation on locale, and date.

NameTypeDescription
locale (required)NSString

Locale for which sync is needed.

date (required)NSDate

Date from where sync data is needed.

completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];


NSDate *date = [NSDate date]; 

[[stack syncLocale:ENGLISH_UNITED_STATES from:date completion:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")


let date = Date.date() 

stack.syncLocale(ENGLISH_UNITED_STATES, from: date, completion: { ( syncStack:SyncStack, error: NSError) in


})

syncOnly:locale:from:completion:

Perform a synchronization operation on specified classes, locale and date.

NameTypeDescription
contentType (required)NSString

ContentType uids of classes to be expected.

locale (required)NSString

Locale for which sync is needed.

date (required)NSDate

Date from where sync data is needed.

completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" <span>environmentName:@"ENVIRONMENT"];</span>

NSArray *contentTypeArray = @[@“product”, @“multifield”]; 

NSDate *date = [NSDate date]; 

[[stack syncOnly: contentTypeArray locale:ENGLISH_UNITED_STATES from:date completion:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")

let contentTypeArray = [“product”, “multifield”]

let date = Date.date() 

stack.syncOnly(contentTypeArray, locale:ENGLISH_UNITED_STATES, from: date, completion: { ( syncStack:SyncStack, error: NSError) in


})

syncOnly:locale:from:publishType:completion:

Perform a synchronization operation on specified classes, locale, date and publishType.

NameTypeDescription
contentType (required)NSString

ContentType uids of classes to be expected.

locale (required)NSString

Locale for which sync is needed.

date (required)NSDate

Date from where sync data is needed.

publishType (required)PublishType

PublishType for which sync is needed.

completionBlock (required)(SyncStack *BUILT_NULLABLE_P syncStack , NSError *BUILT_NULLABLE_P error)

completionBlock called synchronization is done.

Obj-C

Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" 


NSArray *contentTypeArray = @[@“product”, @“multifield”]; 

NSDate *date = [NSDate date]; 

[[stack syncOnly: contentTypeArray locale:ENGLISH_UNITED_STATES from:date publishType:ENTRY_PUBLISHED completion:^(SyncStack * Nullable syncStack, NSError * Nullable error) 


}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")

let contentTypeArray = [“product”, “multifield”]

let date = Date.date() 

stack.syncOnly(contentTypeArray, locale:ENGLISH_UNITED_STATES, from: date, publishType:ENTRY_PUBLISHED, completion: { ( syncStack:SyncStack, error: NSError) in


})