How to Use Image Literal in Xcode 13

How to use Image Literal in the latest Xcode version 13?

Use

#imageLiteral(

without the closing parenthesis, In this way you can add images in Xcode 13.

Why does image literals not work in Xcode 11.2.1?

You need to change the following

diceImageView1.image = 

to

diceImageView1.imageView?.image = 'image literal'

Displaying SF Symbols as an Image Literal?

TL;DR Xcode does not support combining the two.


If you comment the image literal code, you can see that it's actually inserting the following code:

static let image = #imageLiteral(resourceName: )

Attempting to do either of the following does not work:

  • #imageLiteral(resourceName: "trash")
  • #imageLiteral(systemName: "trash")

Therefore, I don't think image literals with SF Symbols are supported as of Xcode 11.3.1.

Literals (Images & Colors) don't work in Xcode

When you type Color Literal, a white box appears. In order to set the required colour, tap on that white box to select the colour from Color Picker.

This is what it looks like:

Sample Image



Related Topics



Leave a reply



Submit