Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Type-safe Oriented Programming
Search
Diego Ventura
April 27, 2016
Technology
32
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Type-safe Oriented Programming
Talk da 17ª edição do CocoaHeads RJ sobre Type-safe Oriented Programming
Diego Ventura
April 27, 2016
Other Decks in Technology
See All in Technology
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
[JAWS-UG彩の国埼玉#12]そろそろ準備する?re:Invent2026をやさしく解説 / reinvent2026-sainokuni
sh_fk2
1
340
PHPカンファレンス関西の招待状 / Invitation to PHP Conference Kansai
ykanoh
0
110
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
150
脆弱性診断って、何をしているの? 〜弱点を見つけて、会社の改善につなげるまで〜
keeg
0
920
分析AIエージェントを育てる、動く環境を育てる
codatum
1
1.1k
初海外で注意すべきこと12選!!!安全快適なre:invent生活にするために
yuuuuuuu168
1
160
UniFi(ユニファイ)AIカメラの現場活用
ludicmind
1
440
AI駆動で「他アプリの音を加工できる」アプリを作った
satomasahiro2005
0
150
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
290
PagerDuty Tech Hub-鳴らすけれど、人は動かない
ezaki
0
170
QA4AI 2026-Oct 生成AI時代の品質保証
tokuty
1
860
Featured
See All Featured
Building an army of robots
kneath
307
47k
What's in a price? How to price your products and services
michaelherold
247
13k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
730
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
How STYLIGHT went responsive
nonsquared
100
6.3k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
460
Game over? The fight for quality and originality in the time of robots
wayneb77
1
300
Docker and Python
trallard
47
4.2k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
540
Transcript
Type-safe oriented programming: Fuja das Strings! Diego Ventura iOS Developer
@ OLX Brasil
E no início eram os xibs…
E no início eram os xibs… • XIB - XML
Interface Builder / Mac OS X Interface Builder • File > New File > View • File’s owner (UIViewController)
E no início eram os xibs… Objective-C Swift [[ViewController alloc]
initWithNibName:@"ViewController" bundle:nil]; ViewController(nibName: "ViewController", bundle: nil)
E depois veio o Storyboard…
E depois veio o Storyboard… • Vários Xibs num mesmo
arquivo • Set subclass na ViewController • Segues facilitaram a vida dos devs
E depois veio o Storyboard… Objective-C Swift UIStoryboard *storyboard =
[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; YourViewControllerClass *viewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; ViewController(nibName: "ViewController", bundle: nil)
Só tem um problema TODOS eles usam Strings
Strings são ruins • Não possui verificação em compile time
• Em times grandes, é mais complicado ter uma padronização • Favorece, e muito, o typo! (i.e MyTypoViewControler)
E aí como faz?
E aí como faz?
E aí como faz?
Type-safe w/ Extensions extension UIViewController { private class var nibNameIdentifier:
String { return NSStringFromClass(self).componentsSeparatedByString(".").last! } class func instantiateFromXib() -> Self { return self.init(nibName: nibNameIdentifier, bundle: nil) } } let welcomeViewController = WelcomeViewController.instantiateFromXib()
Type-safe w/ Extensions
Type-safe w/ Extensions and Generics //Register nib let nib =
UINib(nibName: "MyCustomCellNib", bundle: nil) tableView.registerNib(nib, forCellReuseIdentifier: "MyCustomCellIdentifier") //Dequeue cell var cell = tableView.dequeueReusableCellWithIdentifier(“MyCustomCellIdentifier", forIndexPath: indexPath) as MyCell!
Type-safe w/ Extensions and Generics
Type-safe w/ Extensions and Generics protocol ReusableViewProtocol { static var
reuseIdentifier: String { get } } extension ReusableViewProtocol where Self: UIView { static var reuseIdentifier: String { return NSStringFromClass(self) } }
Type-safe w/ Extensions and Generics protocol ReusableNibLoadableProtocol: class { static
var nibName: String { get } } extension ReusableNibLoadableProtocol where Self: UIView { static var nibName: String { return NSStringFromClass(self).componentsSeparatedByString(".").last! } }
Type-safe w/ Extensions and Generics extension UITableView { func registerClass<T:
UITableViewCell where T: ReusableViewProtocol>(_: T.Type) { registerClass(T.self, forCellReuseIdentifier: T.reuseIdentifier) } func registerNib<T: UITableViewCell where T: ReusableViewProtocol, T: ReusableNibLoadableProtocol>(_: T.Type) { let bundle = NSBundle(forClass: T.self) let nib = UINib(nibName: T.nibName, bundle: bundle) registerNib(nib, forCellReuseIdentifier: T.reuseIdentifier) } }
Demo
Perguntas
Obrigado! Diego Ventura
[email protected]
@venturadiego https://github.com/diegoventura @ PS: Estou vendendo
um MacBook Air