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
実践Protocol-Extension
Search
Shinji Kobayashi
October 06, 2016
Programming
0
70
実践Protocol-Extension
Shinji Kobayashi
October 06, 2016
Tweet
Share
More Decks by Shinji Kobayashi
See All by Shinji Kobayashi
5分でできる UITableViewのDrag & Drop
gentlesoft
0
460
自社コンテンツ配信 のためのWebView Tips
gentlesoft
2
5.5k
UIKitDynamicsの活用法
gentlesoft
0
600
iOS9のUIKitDynamics
gentlesoft
0
43
SwiftでUIKitDynamics
gentlesoft
0
55
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
190
Other Decks in Programming
See All in Programming
スマホから Youtube Shortsを見られないようにする
lemolatoon
27
32k
「ちょっと古いから」って避けてた技術書、今だからこそ読もう
mottyzzz
11
6.7k
TFLintカスタムプラグインで始める Terraformコード品質管理
bells17
2
170
XP, Testing and ninja testing ZOZ5
m_seki
3
670
Swift Concurrency - 状態監視の罠
objectiveaudio
2
520
Devoxx BE - Local Development in the AI Era
kdubois
0
130
Flutterで分数(Fraction)を表示する方法
koukimiura
0
130
(Extension DC 2025) Actor境界を越える技術
teamhimeh
1
250
CSC305 Lecture 05
javiergs
PRO
0
210
私はどうやって技術力を上げたのか
yusukebe
43
18k
Pull-Requestの内容を1クリックで動作確認可能にするワークフロー
natmark
2
510
Six and a half ridiculous things to do with Quarkus
hollycummins
0
170
Featured
See All Featured
Statistics for Hackers
jakevdp
799
220k
Producing Creativity
orderedlist
PRO
347
40k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
9
590
A Modern Web Designer's Workflow
chriscoyier
697
190k
Done Done
chrislema
185
16k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
369
20k
Code Review Best Practice
trishagee
72
19k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Raft: Consensus for Rubyists
vanstee
140
7.1k
Transcript
࣮ફProtocol-Extension Shinji Kobayashi TOPLOG / Gentlesoft shibuya.swift #5
Swift3.0ରԠ ਐΜͰ·͔͢ʁ
ࢲ·ͩख͔ͣͰ͢ɻ (2.3ରԠ͕Α͏͘ऴΘͬͨͱ͜ΖͰ͢)
ͳͥ͜Ε΄ͲͷखؒΛ ͔͚ͯSwiftΛ͏ͷ͔ʁ •Objective-CΑΓ؆ܿʹॻ͚Δ͔Βʁ • ؔܕͷαϙʔτʁ •දݱྗͷߴ͍enumʁ •Protocol-Extensionʂ
Protocol-Extension ͷԿ͕͍͍ʁ
ϓϩάϥϜͷ࣮ํ๏ ΛมԽͤͨ͞
Ͳ͏͍͏෩ʹʁ
֮͑ͯཉ͍͠ศརػೳ •associatedtype •where Self: Hogehoge •Selfܕ
NameɿShinji Kobayashi Twitterɿ@gentlejkov GentleSoft Who are you? http://gentlesoft.net
Work https://toplog.co.jp/ TOPLOG iOS Engineer
TOPLOG APP 2016/3/1 ver.1.0.0 Now ver.2.1.3 100% pure Objective-C 70%
Swift
TOPLOG APP ΩϡϨʔγϣϯ ΦϦδφϧهࣄ
TOPLOG APP ΦϦδφϧهࣄ දࣔ͢Δσʔλҧ͏͕ػೳࣅ͍ͯΔ ΩϡϨʔγϣϯ
TOPLOG APP ΩϡϨʔγϣϯ ΦϦδφϧهࣄදࣔ ࠂදࣔ ΦϦδφϧهࣄ
TOPLOG APP ΩϡϨʔγϣϯ ΦϦδφϧهࣄදࣔProtocol ࠂදࣔProtocol ΦϦδφϧهࣄ
RANKING MY CLIP TOPLOG APIͷΓཁૉ͕एׯҧ͏(ߏಉ͡) Ϧετͷ࣮ํ๏ಉ͡ʢαʔόଆͰΓସ͑ʣ ΦϦδφϧهࣄදࣔ
ΦϦδφϧهࣄදࣔ
ΦϦδφϧهࣄදࣔ APIͷΓͷڞ௨෦ΛProtocolͰఆٛ͠ associatedtypeͰઃఆͨ͠ܕContentsΛ੍͢Δ ContentsܕͷσʔλΛ࣋ͭΫϥεͱͯ͠ ৼΔ͏͜ͱ͕Ͱ͖Δ
ΦϦδφϧهࣄදࣔ Extension
ΦϦδφϧهࣄදࣔ Extension ΦϦδφϧهࣄΛදࣔ͢ΔͨΊͷ ϏδωεϩδοΫΛ·ͱΊͨͷ
ࠂදࣔ Protocol-Extension ࠂΛදࣔ͢ΔͨΊͷ ϏδωεϩδοΫΛ·ͱΊͨͷ
ͭ·Γ Protocol-Extension
ϏδωεϩδοΫΛ ViewController͔Β ࣗવʹΓग़ͤΔ
ExtensionΛUIViewControllerͱͯ͠ѻ͍͍ͨ લड़ͨ͠Protocolݪଇ UIViewControllerͰ࣮͞ΕΔ Extensionͷܕ੍
Extensionͷܕ੍
ExtensionΛUIViewControllerͰ੍ ͜ͷExtensionͰ selfUIViewControllerͱͯ͠ѻ͑Δ Extensionͷܕ੍
ΦϦδφϧهࣄදࣔProtocolͱࠂදࣔProtocol ͷ྆ํΛ࣮͢ΔViewController͕͋Δ ্هProtocolͷ྆ํΛ࣮͢Δ߹ Ұ෦ϩδοΫΛมߋ͍ͨ͠ Extensionͷܕ੍
ඪ४࣮ ಛघ࣮ Extensionͷܕ੍
ඪ४࣮ ಛघ࣮ ಛఆͷProtocolΛ࣮͍ͯ͠Δ࣌ͷ ผϩδοΫ Extensionͷܕ੍
ܕ੍ʹΑΔಛघ࣮ ͷҙ ProtocolʹએݴΛ͓͔ͯ͠ͳ͍ͱ ϙϦϞϑΟοΫʹಈ࡞͠ͳ͍
Selfܕ Protocolʹ͓͍ͯࣗࣗΛࢦ͢ ܕͷ͜ͱ ࣗࣗͷΦϒδΣΫτΛฦ͢ ExtensionͷϝιουΛ࣮Ͱ͖Δ
ڞ௨ͷFactoryϝιου
֮͑ͯཉ͍͠ศརػೳ ϓϩάϥϜΛࣗવʹ ܕ҆શʹ͢ػೳ •associatedtype •where Self: Hogehoge •Selfܕ
·ͱΊ •Protocol-ExtensionΛ͏ࣄͰɺϏδωεϩδοΫ ΛࣗવʹViewController͔ΒΓग़͠ɺඞཁʹԠ ֤ͯ͡ΫϥεʹదԠͤ͞Δࣄ͕Մೳͱͳͬͨ •assosiatedtype, where, SelfܕͳͲͷػೳʹΑΓܕ҆ શͰ෭࡞༻ͷগͳ͍ϩδοΫͷڞ௨Խ͕Ͱ͖Δ