I started studying swift language n there is a command Image Literal to add an image but it's not showing up anything. other than that if I try any other coding thing it automatically gets suggested but image literal is not working at all... I am using Xcode 13. Any leads would be really helpful.
-
What are you typing to try and make it show up? – Fogmeister Sep 27 '21 at 12:33
-
2I just checked myself, and code completion is not currently working for image literals or color literals in Xcode 13. – pkamb Sep 27 '21 at 21:42
-
with each release of a new version of Xcode, it is getting closer and closer to the brick – zslavman Dec 15 '21 at 10:10
4 Answers
For image literals in Xcode 13 type:
#imageLiteral(
The image literal should be displayed and available for picking the image.
The same appears to work for the other literals:
#colorLiteral(
#fileLiteral(
This places the literal in code without code completion. The code completion stopped working on literals for me as well.
After picking an image, comment the line to see the file name, if needed.
-
1Thanks. This seems to be working fine. (I've tested this with Xcode Version 13.2.1 (13C100)) – Rakshitha Muranga Rodrigo Apr 28 '22 at 20:19
#imageLiteral(
Without the closing parenthesis, In this way you can add images in Xcode 13.

- 2,044
- 2
- 19
- 34
try this:
1- solutions
#imageLiteral then it automatically shows the imageFile
and click on it that will show the recent image that you have
in the assets file
2- solutions
UIImage(named: String)
write the image name that you have in the assets file in the place of String

- 44
- 8
-
Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? See the other answers as good examples of how to answer a question like this. – Jeremy Caney Feb 05 '22 at 01:09
Not sure if that's exactly what you're asking about, but... You can add an image to a view with Image() function that takes image file path as argument. You can do all kinds of stuff with it using methods right after the function. This, for example, crops the image into a circle, resizes it, and adds white outline:
Image("<file path>")
.resizable()
.frame(width: screenSize.width / 2,
height: screenSize.width / 2)
.clipShape(Circle())
.overlay(Circle().stroke(Color.white, lineWidth: 5))

- 69
- 10