Slide 25
Slide 25 text
enum Section {
case Birds(row: Bird), Fishes(row: Fish)
enum Bird: Int { case Parrot, Owl, Woodpeckers }
enum Fish: Int { case Carp, Dragonfish }
init?(indexPath: NSIndexPath) {
switch (indexPath.section, indexPath.row) {
case (0, let x):
guard let bird = Bird(rawValue: x) else { return nil }
self = Birds(row: bird)
case (1, let x):
guard let fish = Fish(rawValue: x) else { return nil }
self = Fishes(row: fish)
default: return nil
}
}
var indexPath: NSIndexPath {
switch self {
case .Birds(let row): return NSIndexPath(forRow: row.rawValue, inSection: 0)
case .Fishes(let row): return NSIndexPath(forRow: row.rawValue, inSection: 1)
}
}
}