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
Recoilを剥がしている話
kirik
5
6.8k
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
CSC305 Lecture 26
javiergs
PRO
0
140
Zoneless Testing
rainerhahnekamp
0
120
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
270
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
命名をリントする
chiroruxx
1
410
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
200
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
ドメインイベント増えすぎ問題
h0r15h0
2
330
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
It's Worth the Effort
3n
183
28k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Statistics for Hackers
jakevdp
796
220k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Agile that works and the tools we love
rasmusluckow
328
21k
The World Runs on Bad Software
bkeepers
PRO
65
11k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
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