【发布时间】:2016-05-09 08:36:04
【问题描述】:
我正在尝试在枚举中执行一个函数,但是当执行此代码 ContentType.SaveContent("News") 时,我不断收到以下错误:Use of instance member on type 'ContentType'; did you mean to use a value of type 'ContentType' instead?。为什么我将类型设置为字符串时它不会运行?
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
}
}
}
【问题讨论】: