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 Programming Practice in Swift
Search
Hank Bao
December 20, 2015
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Type-safe Programming Practice in Swift
Swift 类型安全编程实践
2015年12月20日在 SwiftCon AlphaShow 沙龙上的分享
Hank Bao
December 20, 2015
More Decks by Hank Bao
See All by Hank Bao
Notes on Gamification
hankbao
0
130
Reverse Engineering: from Objective-C to Swift
hankbao
2
470
Functional Programming Practice in Swift
hankbao
4
110
Other Decks in Programming
See All in Programming
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
160
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
430
ActionController meets Protocol Buffers
sorah
0
520
Workers Cache を知る
syumai
0
360
Domain-Driven Transformation
hschwentner
2
2.3k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
1k
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
Event is what happens
moro
2
780
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
340
Featured
See All Featured
Writing Fast Ruby
sferik
630
63k
Thoughts on Productivity
jonyablonski
76
5.4k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Typedesign – Prime Four
hannesfritz
42
3.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
570
Paper Plane
katiecoart
PRO
5
54k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Are puppies a ranking factor?
jonoalderson
2
4.1k
Transcript
Swift ᔄࣳਞق ᖫᑕਫ᪢ @hankbao 1
Obj-C ک Swift ౯ժ឴ԧՋԍ! @hankbao 2
ᑮ — C: NULL — Objective-C: nil — Swift: Optional<T>.None
@hankbao 3
Კ — ᖫᦲᲙ — ෙ०ᨳ — ᬩᤈᲙ @hankbao 4
ᖫᦲᲙ @hankbao 5
ෙ०ᨳ @hankbao 6
ᬩᤈᲙ @hankbao 7
Ոᙂ༄ၥ let img = UIImage(named: "project")! @hankbao 8
ᖫᦲ༄ၥ extension UIImage { enum Asset: String { case Favorite
= "favorite" case Project = "project" ... } convenience init(asset: Asset) { ... } } let img = UIImage(asset: .Project) @hankbao 9
ᔄࣳਞقጱᩒრᓕቘ — R.swift — SwiftGen — Shark — Laurine @hankbao
10
ᔄࣳਞق — ᩒრᓕቘ — ᭗Ꭳݷᑍ — ࢶᇆݷᑍ — UI ਁᒧԀ
— ... — AnyObject => T @hankbao 11
DataSource struct User { let id: String let name: String
} struct Channel { let id: String let title: String } @hankbao 12
DataSource class DataSource<Item>: NSObject, UITableViewDataSource { typealias Configure = (cell:
UITableViewCell, item: Item) -> UITableViewCell } tableView.dataSource = DataSource<?>(configure: ...) @hankbao 13
DataSource enum DataItem { case UserItem(user: User) case ChannelItem(channel: Channel)
} @hankbao 14
DataSource protocol ReuseIdentifierType { var reuseID: String { get }
} extension DataItem: ReuseIdentifierType { var reuseID: String { switch self { case .UserItem: return "user_cell" case .ChannelItem: return "channel_cell" } } } @hankbao 15
DataSource class DataSource<Item: ReuseIdentifierType>: NSObject, UITableViewDataSource { func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let item = items[indexPath.row] let cell = tableView.dequeueReusableCellWithIdentifier(item.reuseID, forIndexPath: indexPath) return configure(cell: cell, item: item) } ... } @hankbao 16
݇ᘍᩒා — The Swift Programming Language — WWDC — objc.io
— realm.io @hankbao 17
Thanks @hankbao 18