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
80
Pragmatic Blocks
robbrown
3
86
Other Decks in Programming
See All in Programming
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
Remix on Hono on Cloudflare Workers
yusukebe
1
300
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
140
Realtime API 入門
riofujimon
0
150
最新TCAキャッチアップ
0si43
0
190
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
300
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
970
Featured
See All Featured
A Tale of Four Properties
chriscoyier
156
23k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Building Your Own Lightsaber
phodgson
103
6.1k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Gamification - CAS2011
davidbonilla
80
5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Designing for humans not robots
tammielis
250
25k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
BBQ
matthewcrist
85
9.3k
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