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
Mobile Programming Protocol Extension
Search
yuichiro_takahashi
January 29, 2019
Technology
0
78
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
330
巨大な機能を VIPER + MicroViewController でいい感じに実装した話
yuichirokato
1
780
Mobile Programming Protocol
yuichirokato
0
81
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
あなたの興味は信頼性?それとも生産性? SREとしてのキャリアに悩むみなさまに伝えたい選択肢
jacopen
6
3.2k
(Simutrans) 所要時間ベース経路検索のご紹介
teamhimeh
0
100
ObservabilityCON on the Road Tokyoの見どころ
hamadakoji
0
210
地方企業がクラウドを活用するヒント
miu_crescent
PRO
1
110
Autify Company Deck
autifyhq
2
41k
AWSエンジニアに捧ぐLangChainの歩き方
tsukuboshi
0
220
GitLab SelfManagedをCodePipelineのソースに設定する/SetGitLabSelfManagedtoCodePipeline
norihiroishiyama
1
120
SREとしてスタッフエンジニアを目指す / SRE Kaigi 2025
tjun
15
6.5k
Zenn のウラガワ ~エンジニアのアウトプットを支える環境で Google Cloud が採用されているワケ~ #burikaigi #burikaigi_h
kongmingstrap
18
6.9k
[2024年10月版] Notebook 2.0のご紹介 / Notebook2.0
databricksjapan
0
1.6k
HCP TerraformとAzure:イオンスマートテクノロジーのインフラ革新 / HCP Terraform and Azure AEON Smart Technology's Infrastructure Innovation
aeonpeople
3
990
もし今からGraphQLを採用するなら
kazukihayase
9
4.2k
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Being A Developer After 40
akosma
89
590k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Writing Fast Ruby
sferik
628
61k
Into the Great Unknown - MozCon
thekraken
34
1.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.2k
The World Runs on Bad Software
bkeepers
PRO
67
11k
For a Future-Friendly Web
brad_frost
176
9.5k
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ͷ࣮͕ݺΕΔ