I am currently following Apple Developer Tutorial but i am stuck at the enum color step. My code doesn't have error i followed their code strictly here is a short code similar to my full code.
Problem here is when i call mainColor it never return any color and i always see a default color in all my view. Could you help me with this and why Apple Code give different result?
enum Theme: String {
case bubblegum
case buttercup
case tan
case teal
case yellow
var mainColor: Color {
Color(rawValue)
}
}
if i give my view direct initialized value like .orange it works.
The Color(rawValue)
here is a value of String which equals to Color("color name")
.
Color("color name")
is different from Color.colorname
. You are supposed to create your own colors in the asset folder of your project.
However, I believe that at the start of every tutorial, Apple usually provides resource for the coding part, you should check it, otherwise just create your own colors.
Because Color(rawValue)
needs to have a value in Assets with the name of the rawValue
.
You need a "Color Set" in "Assets" named "bubblegum", etc (case sensitive)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With