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
57
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
720
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
命名をリントする
chiroruxx
1
420
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
良いユニットテストを書こう
mototakatsu
8
2.8k
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
940
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
Recoilを剥がしている話
kirik
5
6.8k
From Translations to Multi Dimension Entities
alexanderschranz
2
130
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
MCP with Cloudflare Workers
yusukebe
2
220
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
Exploring: Partial and Independent Composables
blackbracken
0
100
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Six Lessons from altMBA
skipperchong
27
3.5k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Bash Introduction
62gerente
608
210k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Producing Creativity
orderedlist
PRO
341
39k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Making the Leap to Tech Lead
cromwellryan
133
9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Facilitating Awesome Meetings
lara
50
6.1k
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