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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
610
Fragmented Architectures
denyspoltorak
0
150
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
690
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
170
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
200
CSC307 Lecture 04
javiergs
PRO
0
660
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
230
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
180
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
280
CSC307 Lecture 05
javiergs
PRO
0
500
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
620
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
A Soul's Torment
seathinner
5
2.2k
Utilizing Notion as your number one productivity tool
mfonobong
3
220
A Modern Web Designer's Workflow
chriscoyier
698
190k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
140
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.9k
Odyssey Design
rkendrick25
PRO
1
490
Visualization
eitanlees
150
17k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Making Projects Easy
brettharned
120
6.6k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
170
The Language of Interfaces
destraynor
162
26k
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