The blue color produced by Color.blue
is different from the one produced by Color(.blue)
. Is this a bug in Xcode preview, or do they really present different values? This doesn't apply to blue only but to several colors such as "red".
CodePudding user response:
Yes, the two are different. By command-clicking on the tokens and using Xcode's "Jump to definition" feature, you can see the headers where they are defined.
For Color.blue
:
extension Color {
// ...
/// A context-dependent blue color suitable for use in UI elements.
public static let blue: Color
For Color(.blue)
:
open class UIColor {
// ...
open class var blue: UIColor { get } // 0.0, 0.0, 1.0 RGB
Note that Color.blue
says "context-dependent" -- this will change with various system environments, such as light or dark mode.
Also relevant: https://developer.apple.com/documentation/uikit/uicolor/standard_colors
Also see note in the comments about a deprecation warning.