Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Mobile Programming Protocol Extension
Search
yuichiro_takahashi
January 29, 2019
Technology
0
77
Mobile Programming Protocol Extension
MobileProgrammingの授業で使うスライドです!
yuichiro_takahashi
January 29, 2019
Tweet
Share
More Decks by yuichiro_takahashi
See All by yuichiro_takahashi
App Clip - in a nutshell
yuichirokato
0
310
巨大な機能を VIPER + MicroViewController でいい感じに実装した話
yuichirokato
1
770
Mobile Programming Protocol
yuichirokato
0
79
Mobile Programming enum
yuichirokato
0
160
Mobile Programming Optional
yuichirokato
0
130
Mobile Programming Struct
yuichirokato
0
120
Mobile Programming Initializer Beta
yuichirokato
0
120
Mobile Programming Inheritance
yuichirokato
0
140
Mobile Programing Property & Method
yuichirokato
0
160
Other Decks in Technology
See All in Technology
.NET のUnified AI Building Blocks 入門...!
okazuki
0
130
PFN Company Deck
pfn
PRO
2
140
140年の歴史あるエンタープライズ企業の内製化×マイクロサービス化への航海
yussugi
0
3.5k
Amazon Forecast亡き今、我々がマネージドサービスに頼らず時系列予測を実行する方法
sadynitro
0
220
TypeScript100%で作るMovable Typeプラグイン
usualoma
2
260
実践/先取り「入門 Kubernetes Validating/Mutating Admission Policy」 / CloudNative Days Winter 2024
pfn
PRO
1
130
ONNX推論クレートの比較と実装奮闘記
emergent
0
250
Windows Server 2025 Pay as you Go ライセンスを試す
murachiakira
0
180
LLMの気持ちになってRAGのことを考えてみよう
john_smith
0
190
Bytebaseで実現する データベース管理の効率化
shogo452
1
130
データ共有による新しい価値の創造
iotcomjpadmin
0
180
Postman Flowsで作るAPI連携LINE Bot
miura55
0
220
Featured
See All Featured
Designing for Performance
lara
604
68k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Practical Orchestrator
shlominoach
186
10k
Building Adaptive Systems
keathley
38
2.3k
Bash Introduction
62gerente
608
210k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.3k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Building Applications with DynamoDB
mza
90
6.1k
Speed Design
sergeychernyshev
25
640
Transcript
PROTOCOL EXTENSION MOBILE PROGRAMMING JAN 30TH
1. EXTENSION
ςΩετ EXTENSION? ▸ ҙͷClassStruct, ProtocolΛจࣈ௨Γ֦ுͰ͖Δݴޠػೳͷࣄ ▸ ͕ࣗఆٛͨ͠Class͚ͩͰͳ͘ɺ͢Ͱʹఆٛ͞Ε͍ͯΔClassͳ Ͳ֦ு͢Δ͜ͱ͕Մೳ(UIViewControllerͱ͔) ▸ ͜͜Ͱݴ͏֦ுͱϝιουϓϩύςΟͷՃ,
Protocolͷ࠾༻ Λࢦ͢ ▸ ඇৗʹศརͳػೳͰ͋Δ͕અΛकΒͳ͍֦ுࠇຐज़ͱݺ ΕڪΕΒΕ͍ͯΔ
ςΩετ EXTENSION(จ๏) extension String { } Ωʔϫʔυ extension ʹଓ͚ͯ ֦ு͍ͨ͠Class໊Λऔಘ
ςΩετ EXTENSION(จ๏) extension String { var length: Int { return
self.count } } Ωʔϫʔυ extension ʹଓ͚ͯ ֦ு͍ͨ͠Class໊Λࢦఆ PropertyΛՃͰ͖Δ͕ Computed Property ͷΈ
ςΩετ EXTENSION(จ๏) extension String { var length: Int { return
self.count } func toInt(with defaultValue: Int) -> Int { return Int(self) ?? defaultValue } } Ωʔϫʔυ extension ʹଓ͚ͯ ֦ு͍ͨ͠Class໊Λࢦఆ PropertyΛՃͰ͖Δ͕ Computed Property ͷΈ ϝιουClassͳͲͱಉ͡Α͏ʹՃՄೳ
ςΩετ EXTENSION(จ๏) extension String { var length: Int { return
self.count } func toInt(with defaultValue: Int) -> Int { return Int(self) ?? defaultValue } init(date: Date, format: String) { // ͘ͳΔͷͰׂѪ } } Ωʔϫʔυ extension ʹଓ͚ͯ ֦ு͍ͨ͠Class໊Λࢦఆ PropertyΛՃͰ͖Δ͕ Computed Property ͷΈ ϝιουClassͳͲͱಉ͡Α͏ʹՃՄೳ ΠχγϟϥΠβClassͳͲͱಉ͡Α͏ʹՃՄೳ
ςΩετ EXTENSION(จ๏ͦͷ̎) extension UIViewController: UITableViewDataSource { func numberOfSections(in tableView: UITableView)
-> Int { return 0 } // ͘ͳΔͷͰׂѪ } Class໊ʹଓ͚ͯProtocol໊Λࢦఆ
2. PROTOCOL EXTENSION
ςΩετ PROTOCOL EXTENSION? ▸ ઌ΄Ͳͨ͠ExtensionΛͬͯ ProtocolΛ֦ு͢Δࣄ ▸ ProtocolඇৗʹศརͳػೳͰ͋Δ͕ఆٛ͞ΕͨϝιουΛ ࠾༻͢Δͨͼʹ࣮͠ͳ͍͚ͯ͘ͳ͍ख͕ؒ͋Δ ▸
Protocol ExtensionΛͬͯProtocolʹσϑΥϧτͷ࣮Λ ࣋ͨͤͯखؒΛܰݮ͢Δ͜ͱ͕Ͱ͖Δ ▸
ςΩετ PROTOCOL EXTENSION(จ๏, ఆٛ) protocol DismissDelegate {} ·ͣProtocolΛఆٛ͢Δ͕֦ு͍ͨ͠ϝιουͬͪ͜ʹॻ͔ͳ͍
ςΩετ PROTOCOL EXTENSION(จ๏, ఆٛ) protocol DismissDelegate {} extension DismissDelegate {
} ·ͣProtocolΛఆٛ͢Δ͕֦ு͍ͨ͠ϝιουͬͪ͜ʹॻ͔ͳ͍ extension Ωʔϫʔυʹଓ͚ͯProtocol໊Λࢦఆ
ςΩετ PROTOCOL EXTENSION(จ๏, ఆٛ) protocol DismissDelegate {} extension DismissDelegate {
func dismiss(vc: UIViewController) { vc.dismiss(animated: true, completion: nil) } } ·ͣProtocolΛఆٛ͢Δ͕֦ு͍ͨ͠ϝιουͬͪ͜ʹॻ͔ͳ͍ extension Ωʔϫʔυʹଓ͚ͯProtocol໊Λࢦఆ ֦ு͍ͨ͠ϝιουΛ࣮
ςΩετ PROTOCOL EXTENSION(จ๏, ࠾༻ଆ) class ViewController: UIViewController { } extension
ViewController: DismissDelegate {} ֦ுͨ͠ProtocolΛ࠾༻ͤ͞Δ͕࣮Λॻ͘ඞཁ͕ແ͍ʂʂ
ςΩετ PROTOCOL EXTENSION(จ๏, ࠾༻ଆ) class ViewController: UIViewController { @IBAction func
dismissAction(_ sender: UIButton) { dismiss(vc: self) } } extension ViewController: DismissDelegate {} ֦ுͨ͠ProtocolΛ࠾༻ͤ͞Δ͕࣮Λॻ͘ඞཁ͕ແ͍ʂʂ DismissDelegateͷextensionͷ࣮͕ݺΕΔ