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?

4 Answers4

17

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

user3704425
  • 171
  • 1
  • 4
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).

aheze
  • 24,434
  • 8
  • 68
  • 125
3

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.

01GOD
  • 133
  • 6
  • 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. Thanks – daj mi spokój Nov 17 '22 at 04:48
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