Xcode 12.4: Image Literal returns error message

I have tried to use the Image Literal on Xcode 12.4, and entered the following code:

Code Block
diceImageView1.imageView?.image = imageLiteral(resourceName: "DiceSix")


but it returns an error message which says:
Code Block
Value of type 'UIImageView' has no member 'imageView'

This error message prevents me from completing the build.

Any suggestions on how to handle this error?

Use the following code:-

diceImageView.image = #imageLiteral(

it will automatically set you an arrays of pictures you have set for your project!

Thank you!

Syed Ajaz Mumtaz

If you can't see the image literal shortcut pop up, you can manually write the code for it and Xcode will replace that code with the required image once the code is complete. For example: diceImageView1.image = #imageLiteral(resourceName: "DiceOne") If you are writing the array of image literals, you can write the code for one image literal manually and then copy-paste the code and change the picture manually. Example: diceArray = [#imageLiteral(resourceName: "DiceOne") , #imageLiteral(resourceName: "DiceTwo"), ..... ]

Hello, I had same problem. But I solved it. Here's my solution. You have to write diceImageView.view = #imageLiteral'( Then the Xcode show you to images you can choose

not diceImageView1.image = #imageLiteral( nor diceImageView1.view = #imageLiteral( doesn't work

I had the same issues, after reading through the comments and solutions here (and tweaking it slightly) this worked for me:


diceImageView1.image = #imageLiteral(

the open bracket above was essential to get it to work.

This is interesting, I wonder if this is a bug?

I ran into this earlier on Xcode Version 13.4.1 (13F100). I was going to run instead the #imageLiteral(resourceName: but a funny thing happened. After typing #imageLiteral(resourceName: I see the autocomplete and use it.

I get the following code.  #init(imageLiteralResourceName: <#T##String#>)

When I went to remove the #init( as I thought it was strange and wanted to see what would happen I ended up putting a ( between Literal and Resource, basically entering the following command. #imageLiteral(

Subsequently, you can enter #imageLiteral( and get the box to appear but the autocomplete won't work. However, as soon as you enter the ( it pops the box in place of the code.

Hope this helps someone.

Suddenly the #imageLiteral( pic selection box appears. So it seems the function still exists but is bugged and not loading as it should ( assuming it wasn't removed on purpose for some reason above my beginner pay grade... cause I am making the Dicee App....."

Ola pessoal, para aqueles que por alguma razão estão tentando usar o image literal e ele não busca a opção de selecionar, eu encontrei aqui mesmo no foram a solução. Quando estiver digitando inicie com # e termine com ( isso mesmo...vai funcionar. fica assim #imageLiteral( Observação estou usando o Xcode 13.4.1

In the newest Xcode14.0, you can still use #imageLiteral( and press tab or enter to auto generate the select button, and then double click to choose the image you need.

e.g

diceImageView1.image = #imageLiteral(;
# after press tab/enter and choose the image
diceImageView1.image = imageLiteral(resourceName: "DiceSix");

P.S Don't forget the left bracket and the whitespace around "=" (or double click won't work)

I got quick solution for any Xcode version
step:1 enter all the code in comment //diceImageView1.image = imageLiteral(resourceName: "DiceSix");

step:2 choose your image based on your choice by entering image name in between semicolon

step3: uncomment your line and boom its gonna work for sure

mohammed iftekhar

I am new at coding and new to SWIFT, and I have started the Udemy  course by Dr.Angela Yu. The course is grate but it is in Xcode 13, and I am using Xcode 14, and it is different. After a few chapters I found my self in trouble with Image Literals. didn't see the small icon in the displayed code, I even had to write the "name_of_the_file" . After looking and looking and trying, the only easy way to do it was this.

code:

# imageLiteral() ---->write the pound key# and write imageLiteral and then the brackets()
and then double click in the little image and the display to select an image on the assets folder will appear. !!!! for some reason the displayed suggestions when starting to type imageliteral, does not show this option!!!!!

so:

1)Type : #imageLiteral

  1. then type : ()

A little icon will appear, double click it and select the image from the assets folder.

Glad I can actually add something substantive to the conversation instead of just sneaking in for the answer.

Instead of what was originally was suggested in my version (Version 14.1) it is no more. Simply type the first part of her instructions but then go to the Library'+' in Xcode then click the 'Show the Media Library ' button (looks like a picture) and when you do that on the left your workspace image choices will show. Let me know if this helps!

/Users/eden/Desktop/Screen Shot 2022-12-13 at 4.44.19 PM.png/ /Users/eden/Desktop/Screen Shot 2022-12-13 at 4.44.05 PM.png

Xcode 12.4: Image Literal returns error message
 
 
Q