我正在尝试检查类型字符串是否等于num字符串,但是我似乎无法弄清楚如何根据枚举的rawValues检查类型。到目前为止,我已经做到了:
但是我不断 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")
}
}
}
您可以通过enum
在开关中使用的原始值来解决此问题:
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
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句