AssetLibrary

View as Markdown

AssetLibrary

AssetLibrary class to fetch details of files on Contentstack server.

NameTypeDescription
cachePolicy CachePolicy

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

setHeader:forKey:

Set a header for AssetLibrary

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"];

AssetLibrary * asset = [stack assetLibrary];

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

Swift

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

let asset = stack.assetLibrary()

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

addHeadersWithDictionary:

Set a header for AssetLibrary

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" environmentName:@"ENVIRONMENT"];

AssetLibrary * asset = [stack assetLibrary];

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

Swift

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

let asset = stack.assetLibrary()

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

removeHeaderForKey:

Removes a header from this AssetLibrary

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"];

AssetLibrary * asset = [stack assetLibrary];

[asset removeHeaderForKey:@"key"];

Swift

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

let asset = stack.assetLibrary()

asset.removeHeaderForKey("key")

sortWithKey:orderBy:

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

NameTypeDescription
key (required)NSString

field uid based on which the ordering should be done.

order (required)OrderBy

ascending or descending order in which results should come.

Obj-C

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

AssetLibrary* asset = [stack assetLibrary];

[asset sortWithKey:@"updated_at" orderBy:Ascending];

Swift

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

var asset:AssetLibrary = stack.assetLibrary()

asset.sortWithKey("updated_at" orderBy:Ascending)

objectsCount

Provides only the number of assets.

Obj-C

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


AssetLibrary * asset = [stack assetLibrary];

[asset objectsCount];

Swift

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


let asset = stack.assetLibrary()

asset.objectsCount()

includeCount

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

Obj-C

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


AssetLibrary * asset = [stack assetLibrary];

[asset includeCount];

Swift

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


let asset = stack.assetLibrary()

asset.includeCount()

includeRelativeUrls

This method includes the relative url of assets.

Obj-C

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


AssetLibrary * asset = [stack assetLibrary];

[asset includeRelativeUrls];

Swift

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


let asset = stack.assetLibrary()

asset.includeRelativeUrls()

includeFallback

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

Obj-C

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


AssetLibrary * asset = [stack assetLibrary];

[asset includeFallback];

Swift

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


let asset = stack.assetLibrary()

asset.includeFallback()

includeBranch

Retrieve the branch for the published content.

Obj-C

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


AssetLibrary * asset = [stack assetLibrary];

[asset includeBranch];

Swift

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


let asset = stack.assetLibrary()

asset.includeBranch()

locale:

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

NameTypeDescription
locale (required)NSString

Language enum for all language available.

Obj-C

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


AssetLibrary * asset = [stack assetLibrary];

[asset locale:@"en-us"];

Swift

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


let asset = stack.assetLibrary()

asset.locale("en-us")

fetchAll:

This method provides all the assets.

NameTypeDescription
completionBlock (required)(void ( ^ ) ( ResponseType type , NSArray<Asset*> *BUILT_NULLABLE_P result , NSError *BUILT_NULLABLE_P error ))

Block to be called once operation is done.

Obj-C

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


AssetLibrary * asset = [stack assetLibrary];

[asset fetchAll:^(ResponseType type, NSArray *result, NSError *error) {


}];

Swift

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


let asset = stack.assetLibrary()

asset.fetchAll { (responseType, result!, error!) -> Void in


})

where:

The where() method retrieves the assets from the stack using any other field UID of the assets.

NameTypeDescription
fieldNSString

Field UID of the Asset

valueNSObject

The value to match for the field.

Obj-C

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

AssetLibrary * asset = [stack assetLibrary];

[asset where:@"fieldName"equalTo:@"Value"];

[asset fetchAll:^(ResponseType type, NSArray *result, NSError *error) {

if (error) { 

   NSLog(@"Error: %@", error.localizedDescription); 

} else {

   NSLog(@"Fetched assets: %@", result); }

}];

Swift

let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")
let asset = stack.assetLibrary()
asset.where("fieldName",equalTo:"Value")
asset.fetchAll { (responseType, result, error) in
if let error = error {
     print("Error: \(error.localizedDescription)") 
  } else { 
     print("Fetched assets: \(result)") 
  } 
}