Ios Swift自定义UITableViewController:开关语句案例标签节枚举

Ios Swift自定义UITableViewController:开关语句案例标签节枚举,ios,uitableview,swift,enums,switch-statement,Ios,Uitableview,Swift,Enums,Switch Statement,为了使我的代码更具可读性和可维护性,对于类型为Int的控制表达式的switch语句中的大小写标签,使用标签代替硬编码的Ints的最佳方法是什么 例如,在我的设置StableViewController中,我尝试了 enum Section : Int { case Phone case LogOut case DeleteAccount } 在–tableView:didSelectRowAtIndexPath: switch indexPath.section { c

为了使我的代码更具可读性和可维护性,对于类型为
Int
的控制表达式的switch语句中的大小写标签,使用标签代替硬编码的
Int
s的最佳方法是什么

例如,在我的
设置StableViewController
中,我尝试了

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'

在开关中,不能简单地使用
indexPath.section
,因为它与枚举的类型不同


使用
开关节(rawValue:indexPath.Section)

在开关中,不能简单地使用
indexPath.section,因为它与枚举的类型不同


使用
开关节(rawValue:indexPath.Section)

如果让section=section(rawValue:indexPath.section){switch section{}}
而不是使用!如果让section=section(rawValue:indexPath.section){switch section{}}而不是使用!如果你得到一个意外的分区号,就会崩溃。