Steven Blue
Steven Blue

Reputation: 39

Use Color in Text() the right way

How do I show my Color data in Text() view the right way? I tried 3 methods but not work for all.

Error = Initializer 'init(_:)' requires that 'Color' conform to 'StringProtocol'

var body: some View {
    Text("\(colorΩ)")
    Text(String(colorΩ))
    Text(colorΩ)   
}

Upvotes: 1

Views: 81

Answers (2)

Steven-Carrot
Steven-Carrot

Reputation: 3051

You can also do it in another way similar to @Asperi answer:

Text(colorΩ.description)

Upvotes: 1

Asperi
Asperi

Reputation: 257493

The goal is not clear but a possible variant is

Text(String(describing: colorΩ))

Tested with Xcode 14 / iOS 16

demo

Upvotes: 3

Related Questions