AssetLibrary Class Reference

Inherits from NSObject
Declared in AssetLibrary.h

Properties

  cachePolicy

property to assign cache policy like CACHE_THEN_NETWORK, NETWORK_ELSE_CACHE, NETWORK_ONLY, etc.

@property (nonatomic, assign) CachePolicy cachePolicy

Declared In

AssetLibrary.h

Sorting

– sortWithKey:orderBy:

Sorts the assets in the given order on the basis of the specified field.

- (void)sortWithKey:(NSString *)key orderBy:(OrderBy)order

Parameters

key

field uid based on which the ordering should be done.

order

ascending or descending order in which results should come.

Discussion

  //Obj-C
  [assetLib sortWithKey:@"updated_at" orderBy:Ascending];

  //Swift
  assetLib.sortWithKey("updated_at" orderBy:Ascending)

Declared In

AssetLibrary.h

Include

– objectsCount

Provides only the number of assets.

- (void)objectsCount

Discussion

  //Obj-C
  [assetLib objectsCount];

  //Swift
  assetLib.objectsCount()

Declared In

AssetLibrary.h

– includeCount

This method also includes the total number of assets returned in the response.

- (void)includeCount

Discussion

  //Obj-C
  [assetLib includeCount];

  //Swift
  assetLib.includeCount()

Declared In

AssetLibrary.h

– includeRelativeUrls

This method includes the relative url of assets.

- (void)includeRelativeUrls

Discussion

  //Obj-C
  [assetLib includeRelativeUrls];

  //Swift
  assetLib.includeRelativeUrls()

Declared In

AssetLibrary.h

– includeFallback

Retrieve the published content of the fallback locale entry if the entry is not localized in specified locale.

- (void)includeFallback

Discussion

  //Obj-C
  [assetLib includeRelativeUrls];

  //Swift
  assetLib.includeRelativeUrls()

Declared In

AssetLibrary.h

– locale:

This method provides all the assets for the specified language in the response.

- (void)locale:(NSString *)locale

Parameters

locale

Language enum for all language available.

Discussion

  //Obj-C
  [assetLib includeRelativeUrls];

  //Swift
  assetLib.includeRelativeUrls()

Declared In

AssetLibrary.h

Manually set headers

– setHeader:forKey:

Set a header for AssetLibrary

- (void)setHeader:(NSString *)headerValue forKey:(NSString *)headerKey

Parameters

headerValue

The header key

headerKey

The header value

Discussion

 //'blt5d4sample2633b' is a dummy Stack API key

 //Obj-C
 Stack *stack = [Contentstack stackWithAPIKey:@"blt5d4sample2633b" accessToken:@"blt3esampletokeneb02" environmentName:@"dummy"];
 AssetLibrary *assetLib = [stack assetLibrary];
 [assetLib setHeader:@"MyValue" forKey:@"My-Custom-Header"];

 //Swift
 var stack:Stack = Contentstack.stackWithAPIKey("blt5d4sample2633b", accessToken:"blt3esampletokeneb02", environmentName:@"dummy")
 var assetLib:AssetLibrary = stack.assetLibrary()
 assetLib.setHeader("MyValue", forKey: "My-Custom-Header")

Declared In

AssetLibrary.h

– addHeadersWithDictionary:

Set a header for AssetLibrary

- (void)addHeadersWithDictionary:(NSDictionary<NSString*,NSString*> *)headers

Parameters

headers

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

Discussion

 //'blt5d4sample2633b' is a dummy Stack API key

 //Obj-C
 Stack *stack = [Contentstack stackWithAPIKey:@"blt5d4sample2633b" accessToken:@"blt3esampletokeneb02" environmentName:@"dummy"];
 AssetLibrary *assetLib = [stack assetLibrary];
 [assetLib addHeadersWithDictionary:@{@"My-Custom-Header": @"MyValue"}];

 //Swift
 var stack:Stack = Contentstack.stackWithAPIKey("blt5d4sample2633b", accessToken:"blt3esampletokeneb02", environmentName:@"dummy")
 var assetLib:AssetLibrary = stack.assetLibrary()
 assetLib.addHeadersWithDictionary(["My-Custom-Header":"MyValue"])

Declared In

AssetLibrary.h

– removeHeaderForKey:

Removes a header from this AssetLibrary.

- (void)removeHeaderForKey:(NSString *)headerKey

Parameters

headerKey

The header key that needs to be removed

Discussion

  //'blt5d4sample2633b' is a dummy Stack API key

  //Obj-C
  Stack *stack = [Contentstack stackWithAPIKey:@"blt5d4sample2633b" accessToken:@"blt3esampletokeneb02" environmentName:@"dummy"];
  AssetLibrary *assetLib = [stack assetLibrary];
  [assetLib removeHeaderForKey:@"My-Custom-Header"];

  //Swift
  var stack:Stack = Contentstack.stackWithAPIKey("blt5d4sample2633b", accessToken:"blt3esampletokeneb02", environmentName:@"dummy")
  var assetLib:AssetLibrary = stack.assetLibrary()
  assetLib.removeHeaderForKey("My-Custom-Header")

Declared In

AssetLibrary.h

Fetch Assets

– fetchAll:

This method provides all the assets.

- (void)fetchAll:(void ( ^ ) ( ResponseType type , NSArray<Asset*> *BUILT_NULLABLE_P result , NSError *BUILT_NULLABLE_P error ))completionBlock

Parameters

completionBlock

block to be called once operation is done. The result data contains all the assets.

Discussion

  //Obj-C
  [assetLib fetchAll:^(ResponseType type, NSArray *result, NSError *error) {
  //error for any error description
  //result for reponse data
  }];

  //Swift
  assetLib.fetchAll { (responseType, result!, error!) -> Void in
  //error for any error description
  //result for reponse data
  }

Declared In

AssetLibrary.h