Xcode 13 SwiftUI Color Literal missing
Asked Answered
P

5

18

I am using the Xcode 13 beta and noticed the Color Literal suggestion when trying to choose a color with a picker does not show up (in previous versions I would do Color(Color Literal()) and a color picker would show up. Any thoughts on this?

Pragmaticism answered 10/6, 2021 at 16:55 Comment(2)
Color Literal is not showing up for me either after I updated to Xcode 13. Now I have to do UIColor(named: "name of my color set") to use my customized color.Ostrom
https://mcmap.net/q/488293/-how-to-use-image-literal-in-xcode-13Conflux
C
17

Just type #colorLiteral( for color or #imageLiteral( for image and it will appear immediatly

Cerebro answered 14/10, 2021 at 6:43 Comment(5)
This worked for me with the #colorLiteral( in Xcode 13. I hope they fix the problem! Thank you!Mordecai
not working, it's just showed "Missing arguments for parameters 'red', 'green', 'blue', 'alpha' in call" :/Anywise
@Stevie, try typing in a empty line #colorLiteral, upon typing ( the square icon for literal will show up.Shaddock
this worked on Xcode 14 as wellCoign
It works on an empty line (Xcode 14), but that defeats the purpose when you want to add the color as a parameter.Convertiplane
S
7

Edit (September 26, 2021): As of Xcode 13.0 (13A233), color literals seem to be working now.


It's a known issue. From the release notes:

#colorLiteral, #imageLiteral, and #fileLiteral aren’t rendered. (75248191)

But other than that, note that init(_ color: UIColor) is deprecated, so you can't do something like Color(UIColor.blue). This applies to color literals too.

Instead, use the new init(uiColor: UIColor).

Selfexecuting answered 10/6, 2021 at 16:58 Comment(1)
Thank you hadn't seen the release notesPragmaticism
I
4

Solved like this in Xcode 13.4: Put a SPACE after "=" when assigning. Yes, it's that ridiculous. Then double click to pick a color. So:

var someColor = #colorLiteral(

After that can select a color.

Illona answered 11/8, 2022 at 7:54 Comment(1)
This was exactly what I was looking for, found this answer straight away. I gave up on the colour literal for a long time, but remembered how much easier it was when it was there to use. I wish Apple would have never changed it from colorLiteral, which would autocomplete, to your answer of #colorLiteral( which does not autocomplete. I just have to remember that #colorLiteral( now. ThanksOrlando
F
1

#colorLiteral does not work in certain situations.

such as: bmi = BMI(value: bmiValue, advice: "Eat more pies", color: #colorLiteral() line above doesn't work.

Flashcube answered 27/2, 2024 at 9:13 Comment(1)
came here failing at the same stageFiredog
H
0

Just type #colorLiteral( and then automatically that color swatch is generating. Here you have a clear example:

enter image description here

My Xcode Version:

enter image description here

My Swift version:

enter image description here

Haygood answered 2/9, 2023 at 16:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.