【发布时间】:2015-05-13 17:14:06
【问题描述】:
为了使我的代码更具可读性和可维护性,在具有Int 类型的控制表达式的 switch 语句中使用标签而不是硬编码 Ints 的案例标签的最佳方法是什么?
例如,在我的SettingsTableViewController 中,我尝试过
enum Section : Int {
case Phone
case LogOut
case DeleteAccount
}
在– tableView:didSelectRowAtIndexPath:
switch indexPath.section {
case .Phone:
// Push EditPhoneViewController
case .LogOut:
// Log out
case .DeleteAccount:
// Present action-sheet confirmation
}
但出现编译错误
Enum case pattern cannot match values of the non-enum type 'Int'
【问题讨论】:
标签: ios uitableview swift enums switch-statement