NSDataAsset
Asset Catalogs allow you to organize resources according to the characteristics of the current device. For a given image, you can provide different files depending on the device (iPhone, iPad, Apple Watch, Apple TV, Mac), screen resolution (@2x / @3x), or color gamut (sRGB / P3). For other kinds of assets, you might offer variations depending on the available memory or version of Metal. Just request an asset by name, and the most appropriate one is provided automatically.
Asset catalogs in Xcode let you store not just images but also data files like JSON. This helps apps load faster on first launch by avoiding network calls.
To use it, add a new data set to your asset catalog. Drag in your file, such as a JSON list of colours. Access it in code with NSDataAsset(name: "YourAssetName").data.
For devices with wide-gamut screens, provide different versions by gamut in the attributes inspector.
Keep data fresh with a script that downloads updates and runs in your build process.
For large files, compress them with gzip. Update the type identifier and decompress in code.
This method beats slow networks. It ensures quick starts, which keeps users from leaving.
Category:
Tags:
Year: