Swift version: 5.1
Xcode asset catalogs are a smart and efficient way to bring together your artwork in a single place. But they are also optimized for performance: when your app is built, your assets converted to an optimized binary format for faster loading, so they are recommended for all kinds of apps unless you have a specific reason to avoid them. (Note: SpriteKit games should texture atlases if possible.
If you don't already have an asset catalog in your project, you can create one by right-click on your project and choosing New File. From "iOS" choose "Resource" then Asset Catalog, then click Next and name your catalog. You can now select your new asset catalog in Xcode, and drag pictures directly into it.
Images stored inside asset catalog all retain their original filename, minus the path extension part. For example, "taylor-swift.png" will just appear as "taylor-swift" inside your asset catalog, and that's how you should refer to it while loading too.
Asset catalogs automatically keep track of Retina and Retina HD images, but it's recommended that you name your images smartly to help make the process more smooth: taylor-swift.png, firstname.lastname@example.org and email@example.com are the best way to name your files for standard, Retina and Retina HD resolutions respectively.
SPONSORED Catch bugs as soon as they happen and know exactly why a crash occurred by integrating Instabug's SDK in one minute. You will automatically receive device data, network logs, and reproduction steps with every bug and crash report.
Available from iOS 7 – see Hacking with Swift tutorial 2
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.