Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Data Source Combinators
Search
Rob Brown
April 02, 2015
Programming
2
68
Data Source Combinators
Eliminating the boilerplate from UITableView and UICollectionView.
Rob Brown
April 02, 2015
Tweet
Share
More Decks by Rob Brown
See All by Rob Brown
High-level Concurrency
robbrown
1
59
Elixir
robbrown
1
220
MVVM
robbrown
3
250
Reactive Cocoa
robbrown
2
140
UIKit Dynamics
robbrown
0
67
iOS State Preservation and Restoration
robbrown
5
730
Anti-Patterns
robbrown
3
120
Core Animation: Beyond the Basics
robbrown
1
80
Pragmatic Blocks
robbrown
3
88
Other Decks in Programming
See All in Programming
shadcn/uiを使ってReactでの開発を加速させよう!
lef237
0
370
traP の部内 ISUCON とそれを支えるポータル / PISCON Portal
ikura_hamu
0
230
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
0
120
functionalなアプローチで動的要素を排除する
ryopeko
1
780
SpringBoot3.4の構造化ログ #kanjava
irof
1
540
chibiccをCILに移植した結果 (NGK2025S版)
kekyo
PRO
0
190
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
440
ファインディの テックブログ爆誕までの軌跡
starfish719
1
680
Fixstars高速化コンテスト2024準優勝解法
eijirou
0
190
ecspresso, ecschedule, lambroll を PipeCDプラグインとして動かしてみた (プロトタイプ) / Running ecspresso, ecschedule, and lambroll as PipeCD Plugins (prototype)
tkikuc
2
2.2k
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
1
780
“あなた” の開発を支援する AI エージェント Bedrock Engineer / introducing-bedrock-engineer
gawa
9
1.1k
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
We Have a Design System, Now What?
morganepeng
51
7.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
It's Worth the Effort
3n
184
28k
Rails Girls Zürich Keynote
gr2m
94
13k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
370
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Transcript
Data$Source$Combinators ©"Robert"Brown"March"2015"@robby_brown
Table&Views you're'doing'them'wrong ©"Robert"Brown"March"2015"@robby_brown
Overview 1. The&Hard&Way 2. Code&Architecture&Theory 3. The&Be7er&Way ©"Robert"Brown"March"2015"@robby_brown
Demo ©"Robert"Brown"March"2015"@robby_brown
The$Hard$Way ©"Robert"Brown"March"2015"@robby_brown
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
Cell$Crea'on What's'wrong'with'this? • Duplicate+boilerplate • View+controllers+handle+interac5on,+not+data+ sources • Cells+are+o8en+shared+between+table+views •
Cells+should+handle+their+own+layout ©"Robert"Brown"March"2015"@robby_brown
Cell$Crea'on Why$do$we$see$this$so$o,en? • It's&"standard"&prac.ce • That's&how&I've&always&done&it • My&favorite&tutorial&does&it • Apple&does&it
©"Robert"Brown"March"2015"@robby_brown
Cell$Crea'on Why$do$we$see$this$so$o,en? • It's&really&convenient&for&tutorials&to&be&simple ©"Robert"Brown"March"2015"@robby_brown
Code%Architecture%Theory ©"Robert"Brown"March"2015"@robby_brown
Data$Sources Problems: • Massive(View(Controller • Duplicate(boilerplate ©"Robert"Brown"March"2015"@robby_brown
Data$Sources Solu%on: • Single(responsibility0principle • Combinators • Chain(of(responsibility ©"Robert"Brown"March"2015"@robby_brown
A"class"should"have"only"one" reason"to"change. —"Single)responsibility"principle ©"Robert"Brown"March"2015"@robby_brown
A"class"should"have"only"one" reason"to"change. —"Single)responsibility"principle ©"Robert"Brown"March"2015"@robby_brown
Every&class&should&have& responsibility&over&a&single& part&of&the&func6onality...,& and&that&responsibility&should& be&en6rely&encapsulated&by& the&class.1 —"Single)responsibility"principle 1"Wikipedia ©"Robert"Brown"March"2015"@robby_brown
Combinators • Technique*from*func/onal*programming • Usually*seen*with*parsers • Generally*represent*a*single,*simple*feature • Focus*on*composi/on •
Like*higher>order*func/ons*applied*to*features ©"Robert"Brown"March"2015"@robby_brown
Chain&of&Responsibility • Like&a&chain&of&delegates • A&3>&B&3>&C&3>&D&... • If&A&can't&handle&something,&then&try&B&... • Used&to&create&a&sequence&of&combinators ©"Robert"Brown"March"2015"@robby_brown
The$Be&er$Way ©"Robert"Brown"March"2015"@robby_brown
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
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
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
Cell$Crea'on Why$is$this$be*er? • Fewer&lines&of&code • Boilerplate&removed • Behavior&can&be&changed&with&the&data&source(s) • The&data&source&can&work&with&table&and&collec=on&
views • Easier&to&build&combinators ©"Robert"Brown"March"2015"@robby_brown
Dynamic(Behaviors • Array • Mul)*dimensional2array • Filtering • Reordering •
Edi)ng • Index2)tles ©"Robert"Brown"March"2015"@robby_brown
Considera*ons • The%order%of%combinators%applied%ma4ers%for% performance • Ex:%Create%index%9tles%before%filtering • Some9mes%a%combinator%needs%to%implement%more% than%one%feature%for%performance ©"Robert"Brown"March"2015"@robby_brown
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
Demo ©"Robert"Brown"March"2015"@robby_brown
Summary 1. The&Hard&Way 2. Code&Architecture&Theory 3. The&Be7er&Way ©"Robert"Brown"March"2015"@robby_brown
Ques%ons? ©"Robert"Brown"March"2015"@robby_brown
Resources(to(Learn(More • Source(Code • Combinator • Func2onal(Programming(in(Swi7 • Func2onal(Snippets ©"Robert"Brown"March"2015"@robby_brown
Resources(to(Learn(More • Separa'on*of*Concerns • Cohesion • Orthogonality ©"Robert"Brown"March"2015"@robby_brown