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
440
Functional Programming Practice in Swift
hankbao
4
110
Other Decks in Programming
See All in Programming
学習を成果に繋げるための個人開発の考え方 〜 「学習のための個人開発」のすすめ / personal project for leaning
panda_program
1
110
パスタの技術
yusukebe
1
400
Claude Codeで実装以外の開発フロー、どこまで自動化できるか?失敗と成功
ndadayo
2
1.3k
MCPで実現するAIエージェント駆動のNext.jsアプリデバッグ手法
nyatinte
6
840
コンテキストエンジニアリング Cursor編
kinopeee
1
700
Rancher と Terraform
fufuhu
0
100
MLH State of the League: 2026 Season
theycallmeswift
0
160
tool ディレクティブを導入してみた感想
sgash708
1
150
モバイルアプリからWebへの横展開を加速した話_Claude_Code_実践術.pdf
kazuyasakamoto
0
260
バイブコーディング × 設計思考
nogu66
0
130
ライブ配信サービスの インフラのジレンマ -マルチクラウドに至ったワケ-
mirrativ
2
260
The State of Fluid (2025)
s2b
0
200
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
It's Worth the Effort
3n
187
28k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
Side Projects
sachag
455
43k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
Navigating Team Friction
lara
189
15k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
A designer walks into a library…
pauljervisheath
207
24k
Six Lessons from altMBA
skipperchong
28
4k
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