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.
There is no longer image literal :(
You may try:
Who.What = UIImage(named: "catImage")
I came up with a workaround
Create code snippets for color literal and image literal like below
Color
#colorLiteral()
And add completion shortcut as you want, Example: colorLiteral
.
Do same for Image literal
Image
#imageLiteral()
And add completion shortcut as you want. Call those completion shortcuts in your code to get color
and image
literals.
type Who.What = #imageLiteral( Currently it works like this.
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.
let color = #colorLiteral(red: 0.1411764771, green: 0.3960784376, blue: 0.5647059083, alpha: 1)
let image = #imageLiteral(resourceName: "cherry1")
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
#colorLiteral(red: 0.1411764771, green: 0.3960784376, blue: 0.5647059083, alpha: 1)
© 2022 - 2025 — McMap. All rights reserved.