So 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 dont 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))
- I also tried assigning the constant to a variable… but
nothing worked.
[ So 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…
Thank you for your help in advance
2
Answers
Use
It only works if the
String
value oflernset.color
is defined as aColor Set
inAssets
This
or
References a
static
variable. You would need something likeThen you can call
With "nameHere" being the name of a
Color Set
If you want to use a string you can add an extension to Color :
Usage :