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
910
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
1k
WWDC2019 pre party LT
hirothings
0
2.3k
Swiftへの愛2018
hirothings
1
2.8k
iOSなアーキテクチャVIPERのススメ
hirothings
5
3.2k
Swift2年生
hirothings
4
33k
Swiftへの愛
hirothings
0
34k
Other Decks in Programming
See All in Programming
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
960
RubyLSPのマルチバイト文字対応
notfounds
0
120
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
200
初めてDefinitelyTypedにPRを出した話
syumai
0
420
Jakarta EE meets AI
ivargrimstad
0
120
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
距離関数を極める! / SESSIONS 2024
gam0022
0
290
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Scaling GitHub
holman
458
140k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Into the Great Unknown - MozCon
thekraken
32
1.5k
BBQ
matthewcrist
85
9.3k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
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