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 with アーキテクチャ選定 実践入門 / VIPER Architecture
Search
hirothings
January 21, 2020
Programming
4
920
VIPER with アーキテクチャ選定 実践入門 / VIPER Architecture
iOS Clean Architecture勉強会 sponsored by Sansan
https://connpass.com/event/158269/
の登壇スライドです。
hirothings
January 21, 2020
Tweet
Share
More Decks by hirothings
See All by hirothings
実践Dark Mode対応 / Implementing Dark Mode
hirothings
4
170
iOS標準UIワークショップ / iOS Default UI Workshop
hirothings
3
10k
Modernizing Your UI for iOS 13
hirothings
1
1.1k
WWDC2019 pre party LT
hirothings
0
2.3k
Swiftへの愛2018
hirothings
1
2.9k
iOSなアーキテクチャVIPERのススメ
hirothings
5
3.2k
Swift2年生
hirothings
4
33k
Swiftへの愛
hirothings
0
34k
Other Decks in Programming
See All in Programming
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
Go の GC の不得意な部分を克服したい
taiyow
2
770
Recoilを剥がしている話
kirik
5
6.6k
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
3
1.1k
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
Criando Commits Incríveis no Git
marcelgsantos
2
170
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
310
Security_for_introducing_eBPF
kentatada
0
110
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
690
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
Featured
See All Featured
A Tale of Four Properties
chriscoyier
157
23k
Practical Orchestrator
shlominoach
186
10k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Writing Fast Ruby
sferik
628
61k
Bash Introduction
62gerente
608
210k
Designing for Performance
lara
604
68k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Designing Experiences People Love
moore
138
23k
We Have a Design System, Now What?
morganepeng
51
7.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Transcript
VIPER with ΞʔΩςΫνϟબఆ ࣮ફೖ @hirothings
Agenda • VIPERͱʁ • ͳ࣮ͥͷΞʔΩςΫνϟʹVIPERΛબΜͩͷ͔ • (͓·͚)Embedded Frameworkʹ͍ͭͯ • એ
• ΞʔΩςΫνϟબఆʹ͍ͭͯ
ࣗݾհ • @hirothings (Objective-ͻΖC) • ݩϥʔϝϯళϓϩάϥϚʔ • ౬ΓΛ͜ͷ··͍͍ͯͯ͠ͷ͔ࢥ্ཱ͍ͪژ • ݱࡏiOSσϕϩούʔ
VIPERͱʁ
VIPERͱʁ • View • Interactor • Presenter • Entity •
Router ֤ϨΠϠʔͷ಄จࣈͷΈ߹ΘͤͰ VIPER ͱݺͼ·͢ɻ
VIPERͷಛ • ΫϦʔϯΞʔΩςΫνϟΛiOSΞϓϦʹద༻ͨ͠ΞʔΩςΫ νϟ(1) • ֤ϨΠϠʔInterface(Protocol)ʹґଘ • SOLIDݪଇͷ୯Ұͷݪଇʹجͮ͘ (1) •
“VIPER is an application of Clean Architecture to iOS apps. “ • ग़య: https://www.objc.io/issues/13-architecture/viper/
VIPERͷϨΠϠʔ
VIPERͷϨΠϠʔ: Entity • όϦϡʔΦϒδΣΫτ
VIPERͷϨΠϠʔ: Interactor • PresenterͷϦΫΤετʹԠͯ͡ΞϓϦͷϢʔεέʔ ε͝ͱʹϏδωεϩδοΫΛ࣮ߦ͢Δ • EntityΛ͍ͬͯΔ • Viewͷ͜ͱΒͳ͍
VIPERͷϨΠϠʔ: Presenter • Viewʹର͢ΔϓϨθϯςʔγϣϯϩδοΫΛ࣋ͭ • ViewͱRouter, Interactorͷڮ͠తଘࡏ • View͔Βड͚औͬͨΠϕϯτΛͱʹ •
InteractorʹϦΫΤετ • Routerʹը໘ભҠΛґཔ͢Δ • Interactor͔Βड͚औͬͨσʔλΛViewʹ͢
VIPERͷϨΠϠʔ: Presenter • Viewʹର͢ΔϓϨθϯςʔγϣϯϩδοΫΛ࣋ͭ • ViewͱRouter, Interactorͷڮ͠తଘࡏ • View͔Βड͚औͬͨΠϕϯτΛͱʹ •
InteractorʹϦΫΤετ • Routerʹը໘ભҠΛґཔ͢Δ • Interactor͔Βड͚औͬͨσʔλΛViewʹ͢
VIPERͷϨΠϠʔ: View • View, ViewController • ϓϨθϯςʔγϣϯϩδοΫ࣋ͨͳ͍
VIPERͷϨΠϠʔ: Router • ը໘ભҠΛཧ͢Δ • ֤ϨΠϠʔͷΠϯελϯεΛੜ͠ɺը໘Λඳը͢ Δ(ґଘੑΛͻͱ·ͱΊʹղܾ͢Δ͜͜)
ͳ࣮ͥͷΞʔΩςΫνϟʹ VIPERΛબΜͩͷ͔
• ϧʔςΟϯά͕ͳ͘VCؒͰݸผʹը໘ભҠͤͯ͞ΔͨΊભҠͷϩ δοΫ͕ࢄΒΔ • σʔλͷऔಘɾՃ͚ͩΛ͢Δ͕ͳ͍ • ݁ՌɺϓϨθϯςʔγϣϯϩδοΫͱσʔλʹؔ͢ΔϩδοΫ͕ ࠞࡏ͢Δ • ґଘੑΛͻͱ·ͱΊʹղܾ͢Δ͕ͳ͍
• Α࣮͕ͬͯଐਓԽ͢Δ MVCɺMVVMΞʔΩςΫνϟͰΞ ϓϦΛ࡞ͬͯײͨ͡՝ ͠ͳ͍ͱ..
બఆʹࢸͬͨܦҢ ੍ • ॳظϦϦʔεʹؒʹ߹ΘͤΔʹͦ͜·Ͱ͕࣌ؒͳ͍ લఏ݅ • σʔλόΠϯσΟϯάΛଟ༻͢Δ΄ͲͷΠϯλϥΫςΟϒͳ ΞϓϦͰͳ͍ • API͔ΒσʔλΛऔͬͯग़͚ͩ͢ͷΞϓϦ(ϩʔΧϧDB༻
͠ͳ͍) • ։ൃϝϯόʔ2, 3ਓ • ԣల։͢ΔΞϓϦͷج൫ͱͯ͠ɺϨΠϠʔ͔ͬͪΓ͓ͯ͠ ͘ඞཁ͕͋ͬͨ
બఆʹࢸͬͨܦҢ ઌͷ՝ΈԽͯ͠ղܾ͍ͨ͠ ϨΠϠʔυΞʔΩςΫνϟͷબఆ.. VIPER͕ྑͦ͞͏ αϯϓϧΞϓϦΛ ࡞ͬͯஅ͠·ͨ͠
՝ͱιϦϡʔγϣϯ ࠓ·Ͱͷઃܭʹ๊͍ͨ՝ VIPERͷιϦϡʔγϣϯ ϧʔςΟϯά͕ͳ͍ Router͕୲อͯ͘͠ΕΔ ϓϨθϯςʔγϣϯϩδοΫͱσʔ λʹؔ͢ΔϩδοΫ͕ࠞࡏ Presenter, InteractorͰ໌֬ʹ͞Ε͍ͯΔ ґଘੑΛͻͱ·ͱΊʹղܾ͢Δ͕
ͳ͍ Router͕ΠϯελϯεΛੜ͠ґଘੑΛ·ͱΊΔ ׂΛ୲͍ͬͯΔ ଐਓԽ͢Δ ϨΠϠʔ͕໌֬ͳͨΊଐਓԽͮ͠Β͍
VIPERʹ࣮ͯ͠ࡍΑ͔ͬͨ Routerͷଘࡏ • ը໘ભҠͷίʔυΛView͔ΒͰ͖Δ • ͋ΒΏΔը໘ભҠʹରԠ͕Մೳ(ex. Universal Links͔ΒͷભҠ) • ґଘੑΛͻͱ·ͱΊʹ͢Δ͕͋Δ
Routerʹؔͯ͠ ΞϓϦέʔγϣϯ͚ΞʔΩςΫνϟͷVIPERͰClean Architecture ʹΞυΦϯ͞ΕͨϨΠϠʔͰ͕͢ɺ Routerʹ͍ͭͯৄ͘͠Γ͍ͨํiOSઃܭຊͷApplication CoordinatorͱRouterͷষ͕ࢀߟʹͳΓ·͢ɻ IUUQTQFBLTDDCPPLTJ04@BSDIJUFDUVSF ࠷ߴ!
VIPERʹ࣮ͯ͠ࡍΑ͔ͬͨ ςετ͍࣮͢͠Λ”ޙԡ͠”ͯ͘͠ΕΔ • ֤ϨΠϠʔΛInterfaceͷΈͰґଘͤ͞ΔͨΊɺstub, spyʹมߋ ͍͢͠ • ओʹνΣοΩϯά(खಈςετͷίετ͕͔͔ΔՕॴ)ʹࣗಈςε τΛಋೖ •
ॻ͖ͮΒ͍߹ίʔυʹ͕͋Δ ࢀߟ • ୯ମςετͷϋδϝ • https://speakerdeck.com/yokoyas000/dan-ti-tesutofalsehazime
ςετͷྫ ※આ໌ͷͨΊ؆ུԽͯ͠·͢ Presenterͷςετˠ ɾίετେ ɾϏδωεϩδοΫ - ViewͷҰ؏ͨ͠ςε τ͕Մೳ Interactorͷςετ ɾίετখ
ɾ୯ೖྗ / ग़ྗͷςετ
͞Βʹେن։ൃʹͳΔͱ͡Θ͡Θײ͡ΔϝϦοτ • Domain, DataͱViewͰ୲Λ͚ΒΕͨΓ͢Δ • ෆ֬ఆཁૉʹର͢ΔରԠָ͕ͳͷͰ݁Ռૣ͍ • APIͱซͰ։ൃ͢Δͱ͖=>ελϒͰ੩తͳ࣮ • ViewΛ࡞Γͯ͠Өڹൣғখ
VIPER(Clean Architecture)։ൃͰΑ͍
+Embedded Framework ରԠ • ΞϓϦέʔγϣϯͷϞδϡʔϧׂ • ୯ํʹ͔͠ࢀরͰ͖ͳ͍ͨΊૄ݁߹ͳ࣮͕ڧ੍Ͱ͖Δ Embedded Frameworkͱ •
ը໘ʹؔ࿈͢ΔϨΠϠʔͱؔ࿈͠ͳ͍ϨΠϠʔͰߏΛ͚ͨ • ը໘ʹؔ࿈͠ͳ͍ϨΠϠʔΛผϞδϡʔϧʹׂ ׂͷํ
ਖ਼ׂ͘͢͠Δ͜ͱΑΓը໘୯ҐͰӨڹൣғ͕ࢹ ֮తʹ͔ΔDXΛ༏ઌ Scene • View • Presenter • Interactor •
Router ը໘ʹؔ࿈͠ͳ͍ϨΠϠʔ • API Request • DataStore • Entity • Utility • Components (Button..etc) "QQ ผϞδϡʔϧ
ਖ਼ׂ͘͢͠Δ͜ͱΑΓը໘୯ҐͰӨڹൣғ͕ࢹ ֮తʹ͔ΔDXΛ༏ઌ Scene • View • Presenter • Interactor •
Router ը໘ʹؔ࿈͠ͳ͍ϨΠϠʔ • API Request • DataStore • Entity • Utility • Components (Button..etc) "QQ ผϞδϡʔϧ ඍົͳϥΠϯ͕ͩ རศੑʹدͤͨՕॴ
ϑϧFirebaseͰݸਓΞϓϦ࡞Γ·ͨ͠
ݸਓΞϓϦͷΞʔΩςΫνϟͳΜͰ͔͢ʁ
ݸਓΞϓϦͷΞʔΩςΫνϟͳΜͰ͔͢ʁ MVCͰ͢㊙
ΞʔΩςΫνϟͷબఆʹ͍ͭͯ͏͜ͱ
ΞʔΩςΫνϟͷબఆʹ͍ͭͯ • ΞϓϦͷͱෳࡶ͞ʹΑͬͯऔΔ͖ख๏͕ม Θͬͯ͘Δ
ΞʔΩςΫνϟͷબఆʹ͍ͭͯ ྫ) ചΕΔ͔͔Βͳ͍ݸਓΞϓϦ <։ൃڥ> ɾ1ਓ <ΞϓϦͷෳࡶੑ> ɾγϯϓϧ(͡Όͳ͍ͱϠό͍) <ऩӹ> ɾZERO ചΕΔ͔Ͳ͏͔͔Βͳ͍ΞϓϦʹ͍ͨͦ͏ͳ
ΞʔΩςΫνϟෆཁ
ΞʔΩςΫνϟͷબఆʹ͍ͭͯ ΞϓϦͷʹ߹ΘͤͯΞϓϦͷػೳɾ։ൃ ڥͷෳࡶੑ͕૿͢ "1*ϦΫΤετ ։ൃϝϯόʔ"
ΞʔΩςΫνϟͷબఆʹ͍ͭͯ "1*ϦΫΤετ ։ൃϝϯόʔ" ։ൃϝϯόʔ# ։ൃϝϯόʔ$ ϩʔΧϧ%#อଘ ଟݴޠల։ $* 2" $%
ΞϓϦͷʹ߹ΘͤͯΞϓϦͷػೳɾ։ൃ ڥͷෳࡶੑ͕૿͢
ΞʔΩςΫνϟͷબఆʹ͍ͭͯ ෳ"1*ϦΫΤετ ։ൃϝϯόʔ" ։ൃϝϯόʔ# ։ൃϝϯόʔ$ ϩʔΧϧ%#อଘ ଟݴޠల։ $* 2" $%
ΞϓϦͷʹ߹ΘͤͯΞϓϦͷػೳɾ։ൃ ڥͷෳࡶੑ͕૿͢ ։ൃϝϯόʔ% ίϯϑϦΫτ $4ରԠ ύϑΥʔϚϯε "#ςετ ίʔσΟϯάελΠϧ ͕όϥόϥ ΞϓϦԣల։ ։ൃϝϯόʔ&
ΞʔΩςΫνϟͷબఆʹ͍ͭͯ ԿΛղܾ͍͔ͨ͠ʁ ɺΞϓϦͷͱෳࡶੑʹΑͬͯมΘΔɻ ΞϓϦͷʹ߹ΘͤͨΞʔΩςΫνϟͷબఆɾվળ͕ॏཁɻ
• View • Interactor • Presenter • Entity • Router
࣮ࡍͷϓϩδΣΫτͷվળࣄྫ
• View • Interactor • Presenter • Entity • Router
"1*͚ͩͰͳ͘ϩʔΧϧ͔ Βσʔλऔಘ͢ΔΛϦ ϑΝΫλϦϯά ಉ͡&OUJUZͰը໘͝ͱʹද ࣔ͢Δ༰͕શવҧ͏ +Model +DataStore +Translator ࣮ࡍͷϓϩδΣΫτͷվળࣄྫ Ұ෦'MVYΛಋೖ ผҊ݅
ΞϓϦͷʹ߹ΘͤͯঃʑʹϦϑΝΫλϦϯά͠ɺ ΞʔΩςΫνϟΛ͏·͘औΓೖΕ͍͖ͯ·͠ΐ͏ Fin