'How to use Image Literal in Xcode 13

The most used feature is missing in Xcode 13

Image Literal

#imageLiteral()

these commands do not seem to be working. A similar change has happened for Color Literals as well.



Solution 1:[1]

There is no longer image literal :(

You may try:

Who.What = UIImage(named: "catImage")

Solution 2:[2]

I came up with a workaround

Create code snippets for color literal and image literal like below

Color

#colorLiteral()

colorLiteral

And add completion shortcut as you want, Example: colorLiteral. Do same for Image literal

Image

#imageLiteral()

imageLiteral

And add completion shortcut as you want. Call those completion shortcuts in your code to get color and image literals.

colorLiteral imageLiteral

Solution 3:[3]

type Who.What = #imageLiteral( Currently it works like this.

Solution 4:[4]

I used

UIImage(imageLiteralResourceName: "image_asset_name")

and it works perfectly fine on XCode 13.2.1

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 aheze
Solution 2 Suresh Mopidevi
Solution 3 xeneen
Solution 4 Shishir