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
2.1k
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
3.2k
Komerco-コメルコ-を支える技術
starhoshi
4
6k
実践 Cloud Functions for Firebase
starhoshi
7
5.7k
個人アプリでレビューを高くするためにやっていること
starhoshi
2
1.8k
個人開発を加速させるツール群
starhoshi
54
22k
fastlane 勉強会
starhoshi
0
800
学校の iOS 端末事情
starhoshi
0
2.3k
iOS が fastlane なら Android も fastlane に乗ってみては?
starhoshi
0
2.9k
iOS 開発での Pull Request と テストカバレッジの連携
starhoshi
4
3.3k
Other Decks in Technology
See All in Technology
AIに目を奪われすぎて、周りの困っている人間が見えなくなっていませんか?
cap120
1
430
【OptimizationNight】数理最適化のラストワンマイルとしてのUIUX
brainpadpr
1
260
マルチモーダル基盤モデルに基づく動画と音の解析技術
lycorptech_jp
PRO
4
510
Jamf Connect ZTNAとMDMで実現! 金融ベンチャーにおける「デバイストラスト」実例と軌跡 / Kyash Device Trust
rela1470
0
150
LLMをツールからプラットフォームへ〜Ai Workforceの戦略〜 #BetAIDay
layerx
PRO
1
870
製造業の課題解決に向けた機械学習の活用と、製造業特化LLM開発への挑戦
knt44kw
0
160
LIFF CLIとngrokを使ったLIFF/LINEミニアプリのお手軽実機確認
diggymo
0
230
S3 Glacier のデータを Athena からクエリしようとしたらどうなるのか/try-to-query-s3-glacier-from-athena
emiki
0
180
反脆弱性(アンチフラジャイル)とデータ基盤構築
cuebic9bic
2
160
SRE新規立ち上げ! Hubbleインフラのこれまでと展望
katsuya0515
0
160
LTに影響を受けてテンプレリポジトリを作った話
hol1kgmg
0
290
生成AI時代におけるAI・機械学習技術を用いたプロダクト開発の深化と進化 #BetAIDay
layerx
PRO
1
1k
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
337
57k
Optimising Largest Contentful Paint
csswizardry
37
3.4k
The Cost Of JavaScript in 2023
addyosmani
51
8.7k
Scaling GitHub
holman
461
140k
The Invisible Side of Design
smashingmag
301
51k
What's in a price? How to price your products and services
michaelherold
246
12k
How to Ace a Technical Interview
jacobian
278
23k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
21
1.4k
Designing Experiences People Love
moore
142
24k
Making the Leap to Tech Lead
cromwellryan
134
9.5k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
1k
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
Ҏ্