Share
Embed
Transcript
34 slides
-
ࣗݾհ Name: entaku Job: iOS / AndroidΤϯδχΞͳͲ SIer6 2018/3~ εϙʔπϚονϯάΞϓϦ
2019/3~ CBcloud ྲྀITαʔϏε 2 2021/12~ Voicy Twitter: @entaku_0818 -
VIPER ͱʁ https://cheesecakelabs.com/blog/ios-project-architecture-using-viper/ • VIPER is a backronym for View,
Interactor, Presenter, Entity and Router. It’s basically an approach that implements the Single Responsibility Principle to create a cleaner and more modular structure for your iOS project. The ideia behind this pattern is to isolate your app’s dependencies, balancing the delegation of responsibilities among the entities. • VIPERͱɺViewɺInteractorɺPresenterɺEntityɺRouterͷ಄จࣈΛͱͬͨͷ Ͱ͢ɻجຊతʹɺSingle Responsibility Principleʢ୯ҰݪଇʣΛ࣮͠ɺ iOSϓϩδΣΫτʹΫϦʔϯͰΑΓϞδϡʔϧԽ͞ΕͨߏΛ࡞Γग़ͨ͢ΊͷΞϓ ϩʔνͰ͋Δɻ͜ͷύλʔϯͷഎޙʹ͋Δߟ͑ํɺΞϓϦͷґଘؔΛ ͠ɺΤϯςΟςΟؒͷҕৡͷόϥϯεΛͱΔ͜ͱͰ͢ɻ -
νϟϯωϧৄࡉը໘ /// @mockable protocol ChannelDetailViewProtocol { func setupCustomNavigationBar(channelName: String, channelImageURL:
URL?) func scrollToTop() ϥଆ protocol ChannelDetailPresenterProtocol { func onViewDidLoad() func onViewWillAppear() func onViewDidAppear() func onViewWillDisappear() func onBackButtonTapped() func onRefreshControlTrigger() func onShareButtonTapped() • ViewͰUI্ͷॲཧʹؔ͢ΔϝιουΛ༻ҙ • εςʔλεόʔͳͲ • Presenter͔Βݺͼग़͢ -
/// @mockable protocol ChannelDetailInteractorProtocol { var channel: Channel? { get
} var keyword: String { get } var live: Live? { get } var subscriptionInfo: SubscriptionInfo? { get } func getAllData() ϥଆ protocol ChannelDetailPresenterProtocol { func onViewDidLoad() func onViewWillAppear() func onViewDidAppear() func onViewWillDisappear() func onBackButtonTapped() func onRefreshControlTrigger() func onShareButtonTapped() νϟϯωϧৄࡉը໘ • InteractorͰใऔಘॲཧ·ͨɺσʔλΛ ެ։ • Presenter͔Βݺͼग़͢ -
ࢸΔॴ͔ΒݺΕΔΫϥε /// @mockable protocol AudioControllerProtocol: AnyObject { /// Playing settings
properies var playSpeed: AudioPlaySpeed { get set } var audioSpeaker: AudioSpeaker { get set } var bgm: AudioBGM { get set } var voiceVolume: Float { get set } var bgmVolume: Float { get set } var soundEffectVolume: Float { get set } var isSoundEffectEnabled: Bool { get set } /// Playing info properies var audioStatus: AudioStatus { get } var isPlayingOrLoading: Bool { get } var isVoiceOrBGMPlaying: Bool { get } var elapsedPlaytime: TimeInterval { get set } /// Playlist info properies var audioListStyle: AudioListStyle { get set } var playingChannel: Channel? { get } ϥଆ Ի࠶ੜʹؔ͢Δ͜ͱΛ͜͜Ͱશ͍ͯͬͯ·͢ όοΫάϥϯυ࠶ੜ/࿈ଓ࠶ੜ/ϓϨϛΞϜ ࠓޙػೳՃͨ͠Βઈର૿͑Δ… -
Test ϥଆ https://github.com/Quick/Quick • ར༻ϥΠϒϥϦ • QuickSpec • ςετͷ࣮ߦͰར༻ •
https://github.com/Quick/Quick • mockolo • ϞοΫͷ࡞ʹར༻ • https://github.com/uber/mockolo -
Test class ChannelDetailPresenterSpec: QuickSpec { override func spec() { describe("ChannelDetailPresenter")
{ var presenter: ChannelDetailPresenter! var viewMock: ChannelDetailViewProtocolMock! var interactorMock: ChannelDetailInteractorProtocolMock! var routerMock: ChannelDetailRouterProtocolMock! var audioControllerMock: AudioControllerProtocolMock! var deviceManagerMock: DeviceManagerProtocolMock! ʙʙʙ // Prepare let commonSetupCallCount = viewMock.commonSetupCallCount let setContentBottomInsetCallCount = viewMock.setContentBottomInsetCallCount let showLoadingCallCount = viewMock.showLoadingCallCount let getAllDataCallCount = interactorMock.getAllDataCallCount // Action presenter.onViewDidLoad() // Expect expect(viewMock.commonSetupCallCount) == commonSetupCallCount + 1 expect(viewMock.setContentBottomInsetCallCount) == setContentBottomInsetCallCount + 1 expect(viewMock.showLoadingCallCount) == showLoadingCallCount + 1 expect(interactorMock.getAllDataCallCount) == getAllDataCallCount + 1 ϥଆ • MockΛར༻͠ɺPresenter͔Βҙਤͨ͠View/Interractor/Routerͷϝιο υΛݺͼ͍ͩͯ͠Δ͜ͱΛ֬ೝ -
·ͱΊ • VoicyͰΞʔΩςΫνϟʹVIPERΛ࠾༻͍ͯ͠·͢ • ΞʔΩςΫνϟͷಋೖΛ͔ͨ͠Βͱ͍ͬͯᘳͱ͍͖·ͤΜ • ԻͷॲཧࢸΔॴ͔ΒݺΕͨΓ… • ڞ௨Խ͞ΕͨΫϥε͕͋ͬͨΓ •
PresenterͷςετΛॆ࣮͍ͤͯ͞·͢ • PresenterͷςετվΊͯઃܭΛݟ͖͔͚ͬ͢ʹͳ͍ͬͯ ·͢ • BitriseͰઈରʹCIճ͢Α͏ʹͯ͠·͢