Slide 1

Slide 1 text

VIPER Architecture ͔ΒֶͿ Dependency Injection iOS Test Night #5

Slide 2

Slide 2 text

ࣗݾ঺հ • ຊ໊: ੕઒݈հ • Github: starhoshi • Twitter: @star__hoshi • Classi גࣜձࣾ • -> 8/1 ͔Β ʁʁʁ

Slide 3

Slide 3 text

VIPER ͷ Router ʹ͍ͭͯ IUUQTDIFFTFDBLFMBCTDPNCMPHJPTQSPKFDU BSDIJUFDUVSFVTJOHWJQFS

Slide 4

Slide 4 text

ͬ͘͟Γ VIPER • View • Interactor • Presenter • Entity • Router

Slide 5

Slide 5 text

ͬ͘͟Γ VIPER • View - UIViewController • Interactor - UseCase(Business Logic) • Presenter - View ͱ Interactor Λ஥հ • Entity - Data Structure • Router - ը໘ભҠͱ Dependency Injection

Slide 6

Slide 6 text

ͬ͘͟Γ VIPER • View - UIViewController • Interactor - UseCase(Business Logic) • Presenter - View ͱ Interactor Λ஥հ • Entity - Data Structure • Router - ը໘ભҠͱ Dependency Injection

Slide 7

Slide 7 text

Router ͷ໾ׂ • ը໘ભҠ • ը໘ભҠͱ Dependency Injection

Slide 8

Slide 8 text

͜Μͳ͔Μ͡ IUUQTDIFFTFDBLFMBCTDPNCMPHJPTQSPKFDU BSDIJUFDUVSFVTJOHWJQFS

Slide 9

Slide 9 text

͕࣌ؒͳ͍ͷͰ ཧղ͠΍͘͢͢ΔͨΊ View, Presenter, Router ͚ͩݟ͍͖ͯ·͢

Slide 10

Slide 10 text

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 } }

Slide 11

Slide 11 text

Presenter protocol UserPresentation: class { var router: UserWireframe { get } init(router: UserWireframe) } final class UserPresenter: UserPresentation { let router: UserWireframe init(router: UserWireframe) { self.router = router } }

Slide 12

Slide 12 text

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 } }

Slide 13

Slide 13 text

ؔ܎ੑ • ந৅ʹґଘ͍ͯ͠Δ • ͦΕͧΕ͕ Protocol Λ࣮૷͠ɺ Protocol ʹґଘ͍ͯ͠Δ • Router ͚͕ͩ۩৅ΫϥεΛ Initialize ͍ͯ͠Δ • Router Ͱ DI ͍ͯ͠Δʂ

Slide 14

Slide 14 text

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() } } ❌ ⭕

Slide 15

Slide 15 text

Կ͕خ͍͠ͷ͔

Slide 16

Slide 16 text

ςετ͕ॻ͖΍͘͢ͳͬͨ • Protocol ʹͷΈґଘ͍ͯ͠Δ • Mock ΫϥεΛ࡞ΕΔ • ґଘؔ܎ͷগͳ͍ Testable ͳΞʔΩςΫνϟʹ • ଞͷΞʔΩςΫνϟͰ΋Ԡ༻Ͱ͖Δ

Slide 17

Slide 17 text

ςετίʔυ class UserPresenterSpec: QuickSpec { override func spec() { let router = MockUserRouter() let presenter = UserPresenter(router: router) describe("viewDidLoad") { beforeEach { presenter.viewDidLoad() } it("…") { … } } } }

Slide 18

Slide 18 text

͖ͬ͞ͷίʔυ • ͍Ζ͍Ζ୺ંͬͯΔ • Presenter ͔Β View ʹ఻͑ΒΕͳ͍ͱ͔ • Router ͕ը໘ભҠͰ͖ͳ͍ͱ͔ • ͦ΋ͦ΋ίϯύΠϧ௨Βͳ͍

Slide 19

Slide 19 text

ਅ໘໨ʹ VIPER ͨ͠ίʔυ IUUQTHJUIVCDPNTUBSIPTIJ%FWJDF8BMMQBQFS

Slide 20

Slide 20 text

AppStore ʹ΋ग़ͯΔ

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

https://iosdc.jp/2017/node/1543 Stub ͱ Mock ͷҧ͍ɺͪΌΜ ͱཧղͰ͖͍ͯ·͔͢ʁ

Slide 23

Slide 23 text

VIPER Architecture ͔ΒֶͿ Dependency Injection

Slide 24

Slide 24 text

Ҏ্