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
VIPER Architecture から学ぶ Dependency Injection
Search
star__hoshi
July 26, 2017
Technology
3
2k
VIPER Architecture から学ぶ Dependency Injection
iOS Test Night #5 - connpass
https://testnight.connpass.com/event/59283/
star__hoshi
July 26, 2017
Tweet
Share
More Decks by star__hoshi
See All by star__hoshi
大統一ロガーを利用したサービス開発
starhoshi
0
2.8k
Komerco-コメルコ-を支える技術
starhoshi
4
5.8k
実践 Cloud Functions for Firebase
starhoshi
7
5.6k
個人アプリでレビューを高くするためにやっていること
starhoshi
2
1.6k
個人開発を加速させるツール群
starhoshi
54
22k
fastlane 勉強会
starhoshi
0
710
学校の iOS 端末事情
starhoshi
0
2.2k
iOS が fastlane なら Android も fastlane に乗ってみては?
starhoshi
0
2.8k
iOS 開発での Pull Request と テストカバレッジの連携
starhoshi
4
3k
Other Decks in Technology
See All in Technology
新卒1年目が挑む!生成AI × マルチエージェントで実現する次世代オンボーディング / operation-ai-onboarding
cyberagentdevelopers
PRO
1
160
マネジメント視点でのre:Invent参加 ~もしCEOがre:Inventに行ったら~
kojiasai
0
460
Gradle: The Build System That Loves To Hate You
aurimas
2
140
大規模データ基盤チームのオンプレTiDB運用への挑戦 / dpu-tidb
cyberagentdevelopers
PRO
1
110
visionOSでの空間表現実装とImmersive Video表示について / ai-immersive-visionos
cyberagentdevelopers
PRO
1
110
10分でわかるfreee エンジニア向け会社説明資料
freee
18
520k
ネット広告に未来はあるか?「3rd Party Cookie廃止とPrivacy Sandboxの効果検証の裏側」 / third-party-cookie-privacy
cyberagentdevelopers
PRO
1
130
Automated Promptingを目指すその前に / Before we can aim for Automated Prompting
rkaga
0
110
カメラを用いた店内計測におけるオプトインの仕組みの実現 / ai-optin-camera
cyberagentdevelopers
PRO
1
120
ガバメントクラウド先行事業中間報告を読み解く
sugiim
1
1.3k
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.6k
独自ツール開発でスタジオ撮影をDX!「VLS(Virtual LED Studio)」 / dx-studio-vls
cyberagentdevelopers
PRO
1
180
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
How to Ace a Technical Interview
jacobian
275
23k
Done Done
chrislema
181
16k
Embracing the Ebb and Flow
colly
84
4.4k
Facilitating Awesome Meetings
lara
49
6k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
41
2.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
How to train your dragon (web standard)
notwaldorf
88
5.7k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.6k
Transcript
VIPER Architecture ͔ΒֶͿ Dependency Injection iOS Test Night #5
ࣗݾհ • ຊ໊: ݈հ • Github: starhoshi • Twitter: @star__hoshi
• Classi גࣜձࣾ • -> 8/1 ͔Β ʁʁʁ
VIPER ͷ Router ʹ͍ͭͯ IUUQTDIFFTFDBLFMBCTDPNCMPHJPTQSPKFDU BSDIJUFDUVSFVTJOHWJQFS
ͬ͘͟Γ VIPER • View • Interactor • Presenter • Entity
• Router
ͬ͘͟Γ VIPER • View - UIViewController • Interactor - UseCase(Business
Logic) • Presenter - View ͱ Interactor Λհ • Entity - Data Structure • Router - ը໘ભҠͱ Dependency Injection
ͬ͘͟Γ VIPER • View - UIViewController • Interactor - UseCase(Business
Logic) • Presenter - View ͱ Interactor Λհ • Entity - Data Structure • Router - ը໘ભҠͱ Dependency Injection
Router ͷׂ • ը໘ભҠ • ը໘ભҠͱ Dependency Injection
͜Μͳ͔Μ͡ IUUQTDIFFTFDBLFMBCTDPNCMPHJPTQSPKFDU BSDIJUFDUVSFVTJOHWJQFS
͕࣌ؒͳ͍ͷͰ ཧղ͘͢͢͠ΔͨΊ View, Presenter, Router ͚ͩݟ͍͖ͯ·͢
View protocol UserView: class { var presenter: UserPresentation { get
} init(presenter: UserPresentation) } final class UserViewController: UIViewController, UserView { let presenter: UserPresentation init(presenter: UserPresentation) { self.presenter = presenter } }
Presenter protocol UserPresentation: class { var router: UserWireframe { get
} init(router: UserWireframe) } final class UserPresenter: UserPresentation { let router: UserWireframe init(router: UserWireframe) { self.router = router } }
Router protocol UserWireframe: class { static func assembleModule() -> UIViewController
} final class UserRouter: UserWireframe { static func assembleModule() -> UIViewController { let router = UserRouter() let presenter = UserPresenter(router: router) let view = UserViewController(presenter: presenter) return view } }
ؔੑ • நʹґଘ͍ͯ͠Δ • ͦΕͧΕ͕ Protocol Λ࣮͠ɺ Protocol ʹґଘ͍ͯ͠Δ •
Router ͚͕ͩ۩ΫϥεΛ Initialize ͍ͯ͠Δ • Router Ͱ DI ͍ͯ͠Δʂ
DI ͷୈҰา final class UserPresenter: UserPresentation { let router: UserWireframe
init(router: UserWireframe) { self.router = router } } final class UserPresenter: UserPresentation { let router: UserWireframe init() { self.router = UserRouter() } } ❌ ⭕
Կ͕خ͍͠ͷ͔
ςετ͕ॻ͖͘͢ͳͬͨ • Protocol ʹͷΈґଘ͍ͯ͠Δ • Mock ΫϥεΛ࡞ΕΔ • ґଘؔͷগͳ͍ Testable
ͳΞʔΩςΫνϟʹ • ଞͷΞʔΩςΫνϟͰԠ༻Ͱ͖Δ
ςετίʔυ class UserPresenterSpec: QuickSpec { override func spec() { let
router = MockUserRouter() let presenter = UserPresenter(router: router) describe("viewDidLoad") { beforeEach { presenter.viewDidLoad() } it("…") { … } } } }
͖ͬ͞ͷίʔυ • ͍Ζ͍ΖંͬͯΔ • Presenter ͔Β View ʹ͑ΒΕͳ͍ͱ͔ • Router
͕ը໘ભҠͰ͖ͳ͍ͱ͔ • ͦͦίϯύΠϧ௨Βͳ͍
ਅ໘ʹ VIPER ͨ͠ίʔυ IUUQTHJUIVCDPNTUBSIPTIJ%FWJDF8BMMQBQFS
AppStore ʹग़ͯΔ
None
https://iosdc.jp/2017/node/1543 Stub ͱ Mock ͷҧ͍ɺͪΌΜ ͱཧղͰ͖͍ͯ·͔͢ʁ
VIPER Architecture ͔ΒֶͿ Dependency Injection
Ҏ্