How to load specific image from assets with Swift [duplicate] How to load specific image from assets with Swift [duplicate] ios ios

How to load specific image from assets with Swift [duplicate]


You cannot load images directly with @2x or @3x, system selects appropriate image automatically, just specify the name using UIImage:

UIImage(named: "green-square-Retina")


Since swift 3.0 there is more convenient way: #imageLiterals here is text example. And below animated example from here:

enter image description here


You can easily pick image from asset without UIImage(named: "green-square-Retina").

Instead use the image object directly from bundle.
Start typing the image name and you will get suggestions with actual image from bundle. It is advisable practice and less prone to error.

See this Stackoverflow answer for reference.