enum RepeatDay : String, CustomStringConvertible {
case Monday = "Monday"
case Tuesday = "Tuesday"
case Wednesday = "Wednesday"
case Thursday = "Thursday"
case Friday = "Friday"
case Saturday = "Saturday"
case Sunday = "Sunday"
var description : String { return rawValue }
static let allValues = [Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday]
}
以上是在我的模型中声明的。这将是一个类似的用例,例如在设置闹钟时在股票时钟应用中选择日期。
但是下面有抱怨!
guard let repeatDay = $0 else { return "" }
switch repeatDay {
case .Monday :
break
default:
break
}
如上面的屏幕快照所示,其中
repeatDay
是一个Set。在这种情况下有没有使用switch语句的方法?欢迎任何替代方案。
最佳答案
尝试这个
guard let repeatDay = RepeatDay(rawValue: $0) else { return "" }
switch repeatDay {
case .Monday :
break
default:
break
}
关于swift - 在集合上使用Switch语句(Swift 3),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40372373/