Created
January 8, 2016 06:08
-
-
Save ateliercw/7506eb4278a4536b4567 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class OldTableDataSource: NSObject { | |
} | |
private extension OldTableDataSource { | |
enum Section: Int { | |
case Header, Body, Footer | |
static let numberOfSections = 3 | |
enum HeaderRows: Int { | |
case Row1, Row2 | |
static let numberOfRows = 2 | |
} | |
enum BodyRows: Int { | |
case row1, row2, row3, row4 | |
static let numberOfRows = 4 | |
} | |
enum FooterRows: Int { | |
case row1, row2, row3, row4 | |
static let numberOfRows = 4 | |
} | |
} | |
// Because I'm not exhaustively covering the cases, I'm cheating with a generic | |
func cellForRow<RowType>(row: RowType) -> UITableViewCell { | |
return UITableViewCell() | |
} | |
} | |
extension OldTableDataSource: UITableViewDataSource { | |
func numberOfSectionsInTableView(tableView: UITableView) -> Int { | |
return Section.numberOfSections | |
} | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
guard let section = Section(rawValue: section) else { | |
fatalError() | |
} | |
switch section { | |
case .Header: return Section.HeaderRows.numberOfRows | |
case .Body: return Section.BodyRows.numberOfRows | |
case .Footer: return Section.FooterRows.numberOfRows | |
} | |
} | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
guard let section = Section(rawValue: indexPath.section) else { | |
fatalError() | |
} | |
let cell: UITableViewCell | |
switch section { | |
case .Header: | |
guard let row = Section.HeaderRows.init(rawValue: indexPath.row) else { | |
fatalError() | |
} | |
cell = cellForRow(row) | |
case .Body: | |
guard let row = Section.BodyRows.init(rawValue: indexPath.row) else { | |
fatalError() | |
} | |
cell = cellForRow(row) | |
case .Footer: | |
guard let row = Section.FooterRows.init(rawValue: indexPath.row) else { | |
fatalError() | |
} | |
cell = cellForRow(row) | |
} | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment