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
67
実践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
440
自社コンテンツ配信 のためのWebView Tips
gentlesoft
2
5.4k
UIKitDynamicsの活用法
gentlesoft
0
580
iOS9のUIKitDynamics
gentlesoft
0
41
SwiftでUIKitDynamics
gentlesoft
0
52
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
190
Other Decks in Programming
See All in Programming
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
1k
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
カンファレンスの「アレ」Webでなんとかしませんか? / Conference “thing” Why don't you do something about it on the Web?
dero1to
1
110
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
Jakarta EE meets AI
ivargrimstad
0
190
Arm移行タイムアタック
qnighy
0
340
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Amazon Qを使ってIaCを触ろう!
maruto
0
420
Jakarta EE meets AI
ivargrimstad
0
270
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.8k
距離関数を極める! / SESSIONS 2024
gam0022
0
290
Click-free releases & the making of a CLI app
oheyadam
2
120
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Teambox: Starting and Learning
jrom
133
8.8k
Speed Design
sergeychernyshev
25
620
GraphQLとの向き合い方2022年版
quramy
43
13k
Optimizing for Happiness
mojombo
376
70k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
RailsConf 2023
tenderlove
29
900
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Gamification - CAS2011
davidbonilla
80
5k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
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ܕͳͲͷػೳʹΑΓܕ҆ શͰ෭࡞༻ͷগͳ͍ϩδοΫͷڞ௨Խ͕Ͱ͖Δ