Asset
Asset
The Asset class represents a single asset and fetches its metadata from the delivery API.
Note For files over 4 GB, fileSize may overflow due to 32-bit type limits and may not represent the actual file size.
| Name | Type | Description |
|---|---|---|
| fileName | NSString | Returns the filename of the asset |
| fileSize | unsigned int | Returns the size of the asset file |
| fileType | NSString | Returns the file type of the asset |
| uid | NSString | Returns the unique identifier (UID) of the asset |
| url | NSString | Returns the URL of the asset |
| tags | NSArray<NSString*> | Retrieves the list of tags associated with the asset |
| createdAt | NSDate | Returns the date and time when the asset was created |
| createdBy | NSString | Returns the user who created the asset |
| updatedAt | NSDate | Returns the date and time when the asset was last updated |
| updatedBy | NSString | Returns the user who last updated the asset |
| deletedAt | NSDate | Returns the date and time when the asset was deleted |
| deletedBy | NSString | Returns the user who deleted the asset |
| properties | NSDictionary<NSString*id> |
Returns the full asset object from the API response (all keys and values). The properties above are typed accessors for the main fields in this dictionary. |
setLocale
The setLocale method sets the locale code used when fetching the asset so the response is in the requested language.
| Name | Type | Description |
|---|---|---|
| locale (required) | NSString | User-defined locale code for the request (e.g., en-us). Specifies the language of the content returned during the fetch operation. |
Obj-C
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"]; Asset *asset = [stack assetWithUID:@"ASSET_UID"]; [asset setLocale:@"en-us"];
Swift
let stack = Contentstack.stackWithAPIKey("API_KEY", accessToken: "DELIVERY_TOKEN", environmentName: "ENVIRONMENT")
let asset = stack.assetWithUID("ASSET_UID")
asset.setLocale("en-us")configureWithDictionary
The configureWithDictionary method configures the assets’ in-memory metadata (for example, after a fetch or for local use).
- Request behavior: This method does not modify request parameters for fetch.
- For request parameters: Use setLocale:, includeMetadata, or addParamKey:andValue:.
| Name | Type | Description |
|---|---|---|
| dictionary (required) | NSDictionary<NSString*,id*> | Key–value pairs used to set the asset’s stored metadata (for example, uid, fileName, url). Replaces existing values for the provided keys. |
Obj-C
Stack *stack = [Contentstack stackWithAPIKey: @"API_KEY" accessToken: @"DELIVERY_TOKEN" environmentName: @"ENVIRONMENT" ];
Asset* asset = [stack assetWithUID: @"ASSET_UID" ];
[asset configureWithDictionary:@{ @"key_name" : @"MyValue" }];Swift
let stack:Stack = Contentstack.stackWithAPIKey( "API_KEY" ,accessToken: "DELIVERY_TOKEN" , environmentName: "ENVIRONMENT" ) var asset:Asset = stack.assetWithUID( "ASSET_UID" ) asset.configureWithDictionary([ "key_name" : "MyValue" ])
addParamKey:andValue
The addParamKey:andValue method adds a query parameter key–value pair to the Asset. The SDK sends the parameter with the next fetch request (for example, include_dimension, locale, or other supported API keys).
| Name | Type | Description |
|---|---|---|
| key (required) | NSString | User-defined key for the query parameter. Specifies the key sent during the fetch operation. |
| value (required) | NSString | User-defined value for the query parameter. Specifies the value sent during the fetch operation. |
Obj-C
Stack *stack = [Contentstack stackWithAPIKey: @"API_KEY" accessToken: @"DELIVERY_TOKEN" environmentName: @"ENVIRONMENT" ]; Asset* asset = [stack assetWithUID: @"ASSET_UID" ]; [asset addParamKey:@"include_dimension" andValue:@"true"];
Swift
let stack = Contentstack.stackWithAPIKey("API_KEY", accessToken: "DELIVERY_TOKEN", environmentName: "ENVIRONMENT")
var asset: Asset = stack.assetWithUID("ASSET_UID")
asset.addParamKey("include_dimension", andValue: "true")setHeader:forKey:
The setHeader:forKey sets a header for the Asset.
| Name | Type | Description |
|---|---|---|
| headerValue (required) | NSString | The header value |
| headerKey (required) | NSString | The header key |
No return value. The header is applied to the next fetch requests (e.g., fetch:).
Obj-C
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"]; Asset *asset = [stack assetWithUID:@"ASSET_UID"]; [asset setHeader:@"MyValue" forKey:@"My-Custom-Header"];
Swift
let stack = Contentstack.stackWithAPIKey("API_KEY", accessToken: "DELIVERY_TOKEN", environmentName: "ENVIRONMENT")
var asset: Asset = stack.assetWithUID("ASSET_UID")
asset.setHeader("MyValue", forKey: "My-Custom-Header")addHeadersWithDictionary:
The addHeadersWithDictionary method sets a single header on the Asset.
- Multiple headers: Use addHeadersWithDictionary:.
- Override behavior: Headers set on the Asset override the same header from the Stack for that request only.
| Name | Type | Description |
|---|---|---|
| headers (required) | NSDictionary<NSString*,NSString*> | The headers as dictionary which needs to be added to the application. |
No return value. Headers are applied to subsequent requests (e.g., fetch:).
Obj-C
Stack *stack = [Contentstack stackWithAPIKey: @"API_KEY" accessToken: @"DELIVERY_TOKEN" environmentName: @"ENVIRONMENT" ];
Asset* asset = [stack assetWithUID: @"ASSET_UID" ];
[asset addHeadersWithDictionary:@{ @"My-Custom-Header" : @"MyValue" }];Swift
let stack = Contentstack.stackWithAPIKey("API_KEY", accessToken: "DELIVERY_TOKEN", environmentName: "ENVIRONMENT")
var asset: Asset = stack.assetWithUID("ASSET_UID")
asset.addHeadersWithDictionary(["My-Custom-Header": "MyValue"])removeHeaderForKey:
The removeHeaderForKey removes a header from this Asset.
| Name | Type | Description |
|---|---|---|
| headerKey (required) | NSString | The header key that needs to be removed. |
No return value. The header is no longer sent with subsequent requests.
Obj-C
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"];
Swift
let stack = Contentstack.stackWithAPIKey("API_KEY", accessToken: "DELIVERY_TOKEN", environmentName: "ENVIRONMENT")
var asset:Asset = stack.assetWithUID( "ASSET_UID" )
asset.removeHeaderForKey( "key")includeMetadata
The includeMetadata method Includes metadata in the response body.
Obj-C
Stack *stack = [Contentstack stackWithAPIKey:@"API_KEY" accessToken:@"DELIVERY_TOKEN" environmentName:@"ENVIRONMENT"]; Asset* asset = [stack assetWithUID:@"ASSET_UID"]; [asset includeMetadata];
Swift
let stack:Stack = Contentstack.stackWithAPIKey("API_KEY",accessToken:"DELIVERY_TOKEN", environmentName:@"ENVIRONMENT")
var asset:Asset = stack.assetWithUID("ASSET_UID")
asset.includeMetadata()includeBranch
The includeBranch retrieves the branch for the published content.
No return value. Fallback behavior is applied to the next fetch.
Obj-C
Stack *stack = [Contentstack stackWithAPIKey: @"API_KEY" accessToken: @"DELIVERY_TOKEN" environmentName: @"ENVIRONMENT" ]; Asset* asset = [stack assetWithUID: @"ASSET_UID" ]; [asset includeBranch];
Swift
let stack = Contentstack.stackWithAPIKey("API_KEY", accessToken: "DELIVERY_TOKEN", environmentName: "ENVIRONMENT")
var asset: Asset = stack.assetWithUID("ASSET_UID")
asset.includeBranch()fetch:
The fetch fetches an asset asynchronously (by UID or with a query built on the instance).
| Name | Type | Description |
|---|---|---|
| completionBlock (required) | (void ( ^ ) ( ResponseType type , NSError *BUILT_NULLABLE_P error )) | Block to be called once operation is done. |
No return value. Completion block is called with ResponseType (CACHE or NETWORK) and NSError; on success, the Asset instance is populated with properties (fileName, url, etc.).
Obj-C
let stack = Contentstack.stackWithAPIKey("API_KEY", accessToken: "DELIVERY_TOKEN", environmentName: "ENVIRONMENT")
let asset = stack.assetWithUID("ASSET_UID")
asset.fetch { (responseType, error) -> Void in
if let error = error {
// Handle error
}
}Swift
let stack = Contentstack.stackWithAPIKey("API_KEY", accessToken: "DELIVERY_TOKEN", environmentName: "ENVIRONMENT")
let asset = stack.assetWithUID("ASSET_UID")
asset.fetch { (responseType, error) -> Void in
if let error = error {
// Handle error
}
}