An object from a data set type stored in an asset catalog.


class NSDataAsset : NSObject


The object’s content is stored as a set of one or more files with associated device attributes. These sets can also be tagged for use as on-demand resources.

How Data Assets Are Initialized

Data assets are initialized from a named data set in an asset catalog. You create data sets during app development. Each data set contains one or more data files. Each file has associated attributes for features of the device, including the minimum amount of memory and the version of Metal. When you initialize the data asset, the system selects the data file that best matches the current device.

For more information on the data set type in an asset catalog, see Data Set Type in Asset Catalog Format Reference. For information on adding data sets to asset catalogs, see Adding Data Sets in Asset Catalog Help.

How Data Is Accessed

You access the data file by using the data property. Because the property is of type NSData it provides methods for accessing the raw data only as bytes and ranges of bytes.

To access structured data, convert the bytes into the appropriate format. The system can convert some data types for you. One example is XML data using the initWithData: method of XMLParser. Other data types require code for parsing and converting the raw data. You may need to convert larger data files incrementally.


Initializing the Data Asset

init?(name: NSDataAssetName)

Initializes and returns an object with a reference to the named data asset in an asset catalog.

init?(name: NSDataAssetName, bundle: Bundle)

Initializes and returns an object with a reference to the named data asset that is in an asset catalog in the specified bundle.

Accessing Data

var data: Data

The raw data values in the data asset. (read-only)

Getting Data Asset Information

var name: NSDataAssetName

The name of the data set in the asset catalog. (read-only)

typealias NSDataAssetName

The name of a data asset.

var typeIdentifier: String

The uniform type identifier for the data asset. (read-only)


Inherits From

See Also


class UIImageAsset

A container for a collection of images that represent multiple ways of describing a single piece of artwork.