正如 Korpel 已经回答的那样,目前 Enums 不支持实际的继承。所以不可能让某个 Enum 扩展并继承另一个 enum 的情况。
但是,我要补充一点,Enums 确实支持协议,并且与 Swift 2 中引入的协议扩展和新的面向协议的编程方法(请参阅此视频)一起,实现类似于继承的东西是可能的。这是我经常使用的一种技术,用于定义UITableViewController
由枚举驱动的 :s,指定表的部分以及每个部分中的行,并添加一些有用的行为。例如,请参见以下示例代码:
import UIKit
protocol TableSection {
static var rows: [Self] { get }
var title: String { get }
var mandatoryField: Bool { get }
}
extension TableSection {
var mandatoryTitle: String {
if mandatoryField {
return "\(title)*"
} else {
return title
}
}
}
enum RegisterTableSection: Int, TableSection {
case Username
case Birthdate
case Password
case RepeatPassword
static var rows: [RegisterTableSection] {
return [.Username, .Password, .RepeatPassword]
}
var title: String {
switch self {
case .Username:
return "Username"
case .Birthdate:
return "Date of birth"
case .Password:
return "Password"
case .RepeatPassword:
return "Repeat password"
}
}
var mandatoryField: Bool {
switch self {
case .Username:
return true
case .Birthdate:
return false
case .Password:
return true
case .RepeatPassword:
return true
}
}
}
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return RegisterTableSection.rows.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
guard let row = RegisterTableSection(rawValue: indexPath.row) else {
// This should never happen
return UITableViewCell()
}
let cell = UITableViewCell()
cell.textLabel?.text = row.mandatoryTitle
return cell
}
}
前面的代码将呈现下表:

注意通过实现协议,我们的RegisterTableSection
枚举必须为协议中定义的方法和变量提供实现。最有趣的是,它通过协议扩展继承了变量的默认实现mandatoryTitle
TableSection
我在这里上传了这个例子的源代码