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
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
460
MUSUBIXとは
nahisaho
0
130
2026年 エンジニアリング自己学習法
yumechi
0
130
CSC307 Lecture 06
javiergs
PRO
0
680
Oxlintはいいぞ
yug1224
5
1.3k
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
2.4k
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
500
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
110
Implementation Patterns
denyspoltorak
0
280
ThorVG Viewer In VS Code
nors
0
770
Featured
See All Featured
Accessibility Awareness
sabderemane
0
51
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Balancing Empowerment & Direction
lara
5
890
AI: The stuff that nobody shows you
jnunemaker
PRO
2
250
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
62
49k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
74
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
Making Projects Easy
brettharned
120
6.6k
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