Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Data Source Combinators

Data Source Combinators

Eliminating the boilerplate from UITableView and UICollectionView.

Rob Brown

April 02, 2015

Transcript

30 slides
  1. Cell$Crea'on class CandyTableViewController : UITableViewController { override func tableView(tableView: UITableView,

    numberOfRowsInSection section: Int) -> Int { return self.candies.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell let candy = self.candies[indexPath.row] cell.textLabel!.text = candy.name cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator return cell } } From:&raywenderlich.com ©"Robert"Brown"March"2015"@robby_brown
  2. Cell$Crea'on View%Controller override func viewDidLoad() { super.viewDidLoad() let objects =

    [] // Get objects here tableView.dataSource = BaseDataSource(objects) { (view, indexPath, object) -> Any in return MyCell.cell(view as! UITableView, name: object as! String) } } ©"Robert"Brown"March"2015"@robby_brown
  3. Cell$Crea'on View%Controller override func viewDidLoad() { super.viewDidLoad() let objects =

    [] // Get objects here let base = BaseDataSource(objects) { (view, indexPath, object) -> Any in return MyCell.cell(view as! UITableView, name: object as! String) } self.dataSource = ReorderableDataSource(base) } ©"Robert"Brown"March"2015"@robby_brown
  4. Cell$Crea'on Cell class MyCell: SmartTableViewCell { @IBOutlet weak var titleLabel:

    UILabel! class func cell(tableView: UITableView, name: String) -> Self { let cell = self.cell(tableView) cell.titleLabel.text = name return cell } } ©"Robert"Brown"March"2015"@robby_brown
  5. Dynamic(Behaviors • Array • Mul)*dimensional2array • Filtering • Reordering •

    Edi)ng • Index2)tles ©"Robert"Brown"March"2015"@robby_brown
  6. Example(Combinators • BaseDataSource:#Provides#minimum# func1onality • ChainableDataSource:#Allows#data#source# sequences • FilterableDataSource:#Allows#filtering#(ex.# search#bar)

    • ReorderableDataSource:#Allows#reordering • IndexableDataSource:#Shows#index#1tles ©"Robert"Brown"March"2015"@robby_brown

More Decks by Rob Brown

Other Decks in Programming