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
iOSアプリ開発にもDIツールを!
Search
haptaro
January 29, 2018
Programming
5
1.2k
iOSアプリ開発にもDIツールを!
Otemachi.swift × Kyobashi.swift #02
haptaro
January 29, 2018
Tweet
Share
More Decks by haptaro
See All by haptaro
通信環境が不安定でも心地よい体験を
kotaro
0
91
アニメーション実践入門
kotaro
3
580
はじめてのRxSwift体験記
kotaro
3
640
Swiftで気持ち良く開発したアプリを気持ち良くSubmitする
kotaro
0
7.2k
Other Decks in Programming
See All in Programming
情報漏洩させないための設計
kubotak
4
1.1k
nekko cloudにおけるProxmox VE利用事例
irumaru
3
500
103 Early Hints
sugi_0000
1
280
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
210
iOS開発におけるCopilot For XcodeとCode Completion / copilot for xcode
fuyan777
1
820
Fibonacci Function Gallery - Part 2
philipschwarz
PRO
0
180
return文におけるstd::moveについて
onihusube
1
1.3k
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
270
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
190
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
370
Beyond ORM
77web
10
1.4k
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
450
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
A better future with KSS
kneath
238
17k
YesSQL, Process and Tooling at Scale
rocio
170
14k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Invisible Side of Design
smashingmag
299
50k
Done Done
chrislema
182
16k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Gamification - CAS2011
davidbonilla
80
5.1k
Transcript
iOSΞϓϦ։ൃʹDIπʔϧΛʂ 2018/01/29 Otemachi.swift x Kyobashi.swift #02
ඌ ଠ (@haptaro) - Sansanגࣜձࣾ Eightࣄۀ෦ - ϞόΠϧΞϓϦΤϯδχΞ - iOSϝΠϯɺAndroidগͣͭ͠
2
લఏ ࣮ࡍʹಋೖͨ͠Θ͚Ͱͳ͍ɻ
લఏ ࣮ࡍʹಋೖͨ͠Θ͚Ͱͳ͍ɻ ݕ౼͍ͨ͠ʂ
ભҠઌͷActivityͷϑΟʔϧυʹ@InjectͬͯΞϊςʔγϣϯ͍ͭͯΔͰ͠ΐʁ Dagger͕ίʔυΛࣗಈੜͯ͠ϑΟʔϧυʹΛೖͯ͘͠ΕΔ͔Βɺࣗ ͰੜͤͣʹstartActivity͍͍ͤͯ͞Αʂ ಉ͡ػೳΛiOSͰ։ൃͨ͋͠ͱ AndroidͷίʔυϨϏϡʔʹͯ
!!! (iOSͷͱ͖ͳΜ͔৭ʑ࡞ͬͨͷʹ…)
͔֬ʹAndroidͰDaggerΑ͘ฉ͚͘Ͳɺ iOSͷDIπʔϧͲ͏ͳͷͩΖ͏
iOSͰDIπʔϧΛಋೖ͞Ε͍ͯΔํ
ຊ͓͢Δ͜ͱ - DIͱʁ - iOSΞϓϦ։ൃͰDIπʔϧΛ͏ͳΒ - ͦͷதͰDIKitͷ৮ͬͯΈͨ 9
ͦͦDI(Dependency Injection)ͱʁ
ґଘ͍ͯ͠ΔΦϒδΣΫτΛ֎͔ΒೖΕΔ σβΠϯύλʔϯ
ͨͱ͑ɺ ΦϒδΣΫτAͷΠϯελϯεԽʹΦϒδΣΫτBͱC͕ඞཁͰɺ ΦϒδΣΫτBͷΠϯελϯεԽʹΦϒδΣΫτD͕ඞཁ A C B D
ΦϒδΣΫτάϥϑ: ΦϒδΣΫτͷґଘؔΛද͢πϦʔ A C B D
ͦΕͧΕΦϒδΣΫτΛ֎͔ΒೖΕΔʂ A C B D ϓϩτίϧ
ͦΕͧΕΦϒδΣΫτΛ֎͔ΒೖΕΔʂ A C B D
ͲͷΑ͏ʹΦϒδΣΫτΛೖΕΔͷ͔ʁೖΕํ 16 ɾΠχγϟϥΠβInjectionɾɾɾinit()ܦ༝ͰΦϒδΣΫτΛೖΕΔɻҰ൪Α ͘ݟ͔͚Δ͕ɺViewControllerAppDelegateʹ͑ͳ͍ ɾϓϩύςΟInjectionɾɾɾϓϩύςΟʹΦϒδΣΫτΛೖΕΔ ɾϝιουInjectionɾɾɾϝιουܦ༝ͰΦϒδΣΫτΛೖΕΔ
DI͕͋ΔͱԿ͕خ͍͠ͷʁ
- ΦϒδΣΫτͷґଘؔΛΫϥεͷ֎ʹग़ͤΔͷͰɺϞδϡʔ ϧੑ্͕͕Γ࠶ར༻Ͱ͖Δ - ίϯϙʔωϯτಉ͕࢜ૄ݁߹ʹͳΓมߋʹॊೈʹͳΔ - ΦϒδΣΫτͷࠩ͠ସ͕͑Մೳʹ (ϢχοτςετͷࡍʹϞοΫΦϒδΣΫτͷࠩ͠ସ͑ͳͲ) 18
- DIʮґଘ͍ͯ͠ΔΦϒδΣΫτΛ֎͔ΒೖΕΔ୯ͳΔσβΠ ϯύλʔϯʯ - ΦϒδΣΫτͷೖΕํʹछྨ͕͋Δ 19
ͱ͍͑ɺґଘ͕ؔ૿͖͑ͯͯखಈͰґ ଘΦϒδΣΫτΛDI͍ͯ͘͠ͷ͔…
ͦ͜ͰDIαϙʔτπʔϧ✨
iOSΞϓϦͰ͑ͦ͏ͳDIαϙʔτπʔϧ(Swift) - Swinjectɾɾɾ@yoichitgy͞Μ͕࡞ऀɻDIίϯςφɻݱࡏͷiOSͷDI πʔϧͷσϑΝΫτελϯμʔυʁ - DIKitɾɾɾ@ishkawa͞Μ͕࡞ऀɻ͝ຊਓ͕iOSDC 2017Ͱհ - CleanseɾɾɾSquare 22
ґଘؔͷղܾͷλΠϛϯά 23 ɾಈతDIɾɾɾ࣮ߦ࣌ʹґଘؔͷղܾ ex. Swinject ɾ੩తDIɾɾɾίϯύΠϧ࣌ʹґଘؔͷղܾ ex. DIKit, Cake PatternΛ༻͍ͨDI,
ReaderϞφυΛ༻͍ͨDI
੩తDIಈతDIΑΓԿ͕ྑ͍ͷʁ - ҆શ: ίϯύΠϧ࣌ͷґଘؔͷղܾ͕͞ΕΔͷͰɺສ͕Ұؒҧ͍ͬͯͯ ίϯύΠϧΤϥʔʹͳΓɺ࣮ߦ࣌Ϋϥογϡ͛Δ - ࣮ߦ࣌গ͠ૣ͘: ґଘؔΛղܾͨ͠ίʔυ͕ίϯύΠϧ࣌ʹͰ͖Δͷ Ͱ࣮ߦ࣌ͷΛ্͛ΒΕΔ ͨͩ͠ɺنʹΑͬͯίϯύΠϧ͕࣌ؒ͘ͳΔͱ͍͏σϝϦοτ͋Δ
͔ 24
Swift҆શͳݴޠɻ ͬͺΓίϯύΠϧ࣌ʹґଘؔͷղܾΛ ͍ͨ͠
ίϯύΠϧ࣌ʹίʔυΛࣗಈੜͯ͠ґଘؔ ΛղܾͰ͖ΔDIKitͷExample৮ͬͯΈͨ
ґଘؔΛఆٛ
ґଘؔΛఆٛ
ΠϯελϯεΛఏڙ͢Δ provideϝιουΛఆٛ
Dependency͔ΒϏϧυ࣌ʹ ґଘؔΛղܾ͢ΔίʔυΛࣗಈੜ
Storyboardܦ༝ͷViewController ͷΠϯελϯεԽʹରԠ
Storyboardܦ༝ͷViewController ͷΠϯελϯεԽʹରԠ
ͲͷΑ͏ʹґଘؔΛղܾ͍ͯ͠Δͷ͔ 33 JavaͷΑ͏ʹΞϊςʔγϣϯ͕Swiftʹͳ͍ͷͰϓϩτί ϧΛϚʔΫͱͯ͠༻͠ɺSourceKittenͰίʔυղऍɾੜ ੜ͞ΕͨίʔυͰґଘؔΛղܾ
DIKit৮ͬͯΈͯ - Ϗϧυ࣌ʹίʔυ͕ࣗಈੜ͞ΕΔͷͰɺ࿙Ε͕͋ΔͱίϯύΠϧ ΤϥʔʹͳΔͷͰΘ͔Γ͍͢ - Storyboardܦ༝ͰͷViewControllerΠϯελϯεԽͰ͖Δ - Dagger2SwinjectʹൺΔͱ͔ͳΓγϯϓϧ (ٯʹείʔϓͳͲͷ֓೦ࠓͳ͘ɺDIίϯςφͱ·Ͱ͍͔ͳ͍) 34
·ͱΊ ɾSwiftͳΒͬͺΓίϯύΠϧ࣌ʹґଘؔΛ ղܾ͍ͨ͠ ɾDIKitγϯϓϧͰಋೖίετͦ͏ ɾࠓޙDIKitͷϦϙδτϦWatch͍ͯ͜͠͏
ͨͩ…
ɾͦͦϓϩμΫτͷنෳࡶੑɺϢχοτςετͷ ༗ແʹΑͬͯDIαϙʔτπʔϧΛೖΕͣ·ͣखಈDIͰ ྑ͍͔ ɾDIαϙʔτπʔϧʹΑͬͯػೳͷࠩҟ͕͋ΔͷͰԿ͕ద ͍ͯ͠Δ͔அ͕ඞཁ
DIαϙʔτπʔϧΛ͍ͬͯΔํ ࠙ձʹͰ͓ฉ͔ͤͯԼ͍͞
Your business network
ࢀߟࢿྉ - DIKit: https://github.com/ishkawa/DIKit - ishkawa͞Μͷϒϩά: http://blog.ishkawa.org/2017/09/18/1505701774/ - iOSΞϓϦͷઃܭͱDependency Injection:
https://speakerdeck.com/ yonekawa/iosapurifalseshe-ji-todependency-injection - Swinject: https://github.com/Swinject/Swinject - Dependency Injection in Swift 2.x: https://niconare.nicovideo.jp/watch/kn1091 40