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
66
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
57
Elixir
robbrown
1
220
MVVM
robbrown
3
240
Reactive Cocoa
robbrown
2
140
UIKit Dynamics
robbrown
0
67
iOS State Preservation and Restoration
robbrown
5
710
Anti-Patterns
robbrown
3
110
Core Animation: Beyond the Basics
robbrown
1
79
Pragmatic Blocks
robbrown
3
86
Other Decks in Programming
See All in Programming
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.1k
約9000個の自動テストの 時間を50分->10分に短縮 Flakyテストを1%以下に抑えた話
hatsu38
24
12k
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
290
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
440
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
17
4.3k
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
4
480
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
750
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
180
僕がつくった48個のWebサービス達
yusukebe
20
17k
C++でシェーダを書く
fadis
6
3.8k
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.1k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
410
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
505
140k
It's Worth the Effort
3n
183
27k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.8k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Designing the Hi-DPI Web
ddemaree
280
34k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
YesSQL, Process and Tooling at Scale
rocio
168
14k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
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