class DataSource: NSObject {
var models: [Model] = []
subscript(indexPath: NSIndexPath) -> Model? {
return models.isEmpty ? nil
: models[indexPath.row]
}
}
extension DataSource: UITableViewDataSource {
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell {
switch self[indexPath] {
case .Some(let m):
let cell =
tableView.dequeueReusableCellWithIdentifier("Cell",
forIndexPath: indexPath) as! ModelCell
cell.configure(m)
return cell
default: abort()
}
}
func tableView(tableView: UITableView,
numberOfRowsInSection section: Int) -> Int {
return models.count
}
}