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
71
実践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
470
自社コンテンツ配信 のためのWebView Tips
gentlesoft
2
5.6k
UIKitDynamicsの活用法
gentlesoft
0
610
iOS9のUIKitDynamics
gentlesoft
0
45
SwiftでUIKitDynamics
gentlesoft
0
56
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
190
Other Decks in Programming
See All in Programming
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
200
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
1k
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
300
AgentCoreとHuman in the Loop
har1101
5
240
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
170
Data-Centric Kaggle
isax1015
2
770
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
3.9k
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
130
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
110
CSC307 Lecture 08
javiergs
PRO
0
670
AI時代の認知負荷との向き合い方
optfit
0
160
Featured
See All Featured
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
450
Docker and Python
trallard
47
3.7k
First, design no harm
axbom
PRO
2
1.1k
4 Signs Your Business is Dying
shpigford
187
22k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
220
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.7k
Paper Plane (Part 1)
katiecoart
PRO
0
4.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
170
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
130
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ܕͳͲͷػೳʹΑΓܕ҆ શͰ෭࡞༻ͷগͳ͍ϩδοΫͷڞ௨Խ͕Ͱ͖Δ