I have this String
"green" inside a constant (lernset.color
). I would like to set a .foregroundColor()
to a symbol (systemName: "folder")
inside of a list, so that it has the same color as written inside the constant (lernset.color
).
The problem I get: I don't know how to convert this constant (lernset.color
) which has the datatype of a String
into the datatype of Color
.
I already tried:
.foregroundColor(Color.lernset.color)
.foregroundColor(Color.String(lernset.color))
but nothing worked.
Normally you would type: .foregroundColor(Color.green)
But in this case I want the List
to automatically adapt, so that the Color
could change the way the constant (lernset.color
) changes.
Use
Color(lernset.color)
It only works if the String
value of lernset.color
is defined as a Color Set
in Assets
This
Color.lernset.color
or
Color.green
References a static
variable. You would need something like
extension Color{
static let yourColor: Color = Color("nameHere")
}
Then you can call
Color.yourColor
With "nameHere" being the name of a Color Set