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
Type-safe Programming Practice in Swift
Search
Hank Bao
December 20, 2015
Programming
0
110
Type-safe Programming Practice in Swift
Swift 类型安全编程实践
2015年12月20日在 SwiftCon AlphaShow 沙龙上的分享
Hank Bao
December 20, 2015
Tweet
Share
More Decks by Hank Bao
See All by Hank Bao
Notes on Gamification
hankbao
0
120
Reverse Engineering: from Objective-C to Swift
hankbao
2
450
Functional Programming Practice in Swift
hankbao
4
110
Other Decks in Programming
See All in Programming
Package Management Learnings from Homebrew
mikemcquaid
0
220
AgentCoreとHuman in the Loop
har1101
5
230
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
460
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
610
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.4k
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
690
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
CSC307 Lecture 02
javiergs
PRO
1
780
CSC307 Lecture 01
javiergs
PRO
0
690
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
410
Building Adaptive Systems
keathley
44
2.9k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
440
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
1
50
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
80
4 Signs Your Business is Dying
shpigford
187
22k
Into the Great Unknown - MozCon
thekraken
40
2.3k
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