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.
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.
6
Answers
There is no longer image literal 🙁
You may try:
type Who.What = #imageLiteral(
Currently it works like this.
I came up with a workaround
Create code snippets for color literal and image literal like below
Color
And add completion shortcut as you want, Example:
colorLiteral
.Do same for Image literal
Image
And add completion shortcut as you want. Call those completion shortcuts in your code to get
color
andimage
literals.I used
UIImage(imageLiteralResourceName: "image_asset_name")
and it works perfectly fine on XCode 13.2.1
You need to set a variable at the top of your struct to hold the color and image literals before you use them in the view body.
creating a shortcut is handy but it doesn’t solve the problem of Xcode not allowing literals to be used as parameters to views.
This is a nice feature in Xcode and you may find it cool for small projects, but the best way to handle images, colours and other resources is to look into a package like R.Swift or Swiftgen
https://github.com/SwiftGen/SwiftGen
https://github.com/mac-cain13/R.swift
I prefer swiftgen since R.swift is not currently working with M1 Macs.
I can’t make Xcode auto complete colorLiteral, but you can still use the inline color picker.
This is a workaround which works in Xcode 14.2.
Where you want the color picker, enter any color full
colorLiteral
Xcode will then display the color picker which you can use.