i'm trying to check whether the type string is equal to the num strings, however i cant seem to figure out how i check type against the rawValues of enums. so far i've done this:
However i keep getting Enum case News not found in type String
enum ContentType: String {
case News = "News"
case Card = "CardStack"
func SaveContent(type: String) {
switch type {
case .News:
print("news")
case .Card:
print("card")
}
}
}
You can fix this by using enum's raw value in the switch:
enum ContentType: String {
case News = "News"
case Card = "CardStack"
func SaveContent(type: String) {
switch type {
case ContentType.News.rawValue:
print("news")
case ContentType.Card.rawValue:
print("card")
default:
break
}
}
}
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