Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-7194] #colorLiteral producing unexpected results when explicitly written #49742

Closed
AnthonyLatsis opened this issue Mar 14, 2018 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@AnthonyLatsis
Copy link
Collaborator

Previous ID SR-7194
Radar None
Original Reporter @AnthonyLatsis
Type Bug
Status Resolved
Resolution Invalid
Environment

XCode Version 9.2 (9C40b)

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: f68bab241c74e93a15f5560fb22a116c

Issue Description:

I wasn't sure whether to report this here or in the Bug Reporter, since #colorLiteral is part of the STL, but is implemented only for UIColor. If it has to go to Bug Reporter, please inform me.

Explicitly writing a color literal or pasting it with code

#colorLiteral(red: x, green: y, blue: z, alpha: 1.0)

will produce a color with the following components:

red   = (x > 0 && x <= 1) ? 1 : 0
green = (y > 0 && y <= 1) ? 1 : 0
blue  = (z > 0 && z <= 1) ? 1 : 0

So, for instance, this produces pure red:

#colorLiteral(red: 34.0/255.0, green: 0.0, blue: 0.0, alpha: 1.0)

This – pure magenta:

#colorLiteral(red: 34.0/255.0, green: 0.0, blue: 71.0/255.0, alpha: 1.0)

And this – pure white:

#colorLiteral(red: 34.0/255.0, green: 3.0/255.0, blue: 71.0/255.0, alpha: 1.0)

In other words, if any of the color components is > 0 and <= 1, the result will be a color with that component equal to 1.

@belkadan
Copy link
Contributor

To be clear, are you talking about the behavior of your built app, or of the little color swatch in the Xcode editor?

@AnthonyLatsis
Copy link
Collaborator Author

@belkadan, ah, yes, I just checked by visualizing the color on a view – it appears to be the swatch that doesn't match the provided color. Bug Reporter?

@belkadan
Copy link
Contributor

Yeah. I think most likely they'll just decide that a color literal with random expressions in it won't get a swatch at all, but it would be an Xcode-side change regardless. Thanks!

@AnthonyLatsis
Copy link
Collaborator Author

Ok! Done

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants