How can I export RGB components of the ColorPicker view of SwiftUI 2?

Viewed 215

I am using this extension to export RGB components of a Color value which is changed when the user selects a color from the new ColorPicker view for SwiftUI 2:

I'm observing the value change for my color state like this:

@State private var textColor = Color.white

ColorPicker("Text Color", selection: $textColor, supportsOpacity: false)
            .onChange(of: textColor) { newColor in
              print(newColor.components)
            }

But, for some colors in the picker, when the value is printed, it has some negative values in it. What can cause this problem?

(red: 0.9607847332954407, green: 0.9254906177520752, blue: -9.62614990385191e-07, opacity: 1.0)

enter image description here

1 Answers

It's scientific representation of that very small number. (and seems like it overflowed)

it is actually:

-0.0000009626149903851910494267940521240234375 ≅ -0
Related