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
890
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
160
iOS標準UIワークショップ / iOS Default UI Workshop
hirothings
3
10k
Modernizing Your UI for iOS 13
hirothings
1
990
WWDC2019 pre party LT
hirothings
0
2.2k
Swiftへの愛2018
hirothings
1
2.8k
iOSなアーキテクチャVIPERのススメ
hirothings
5
3.1k
Swift2年生
hirothings
4
33k
Swiftへの愛
hirothings
0
34k
Other Decks in Programming
See All in Programming
GraphQL あるいは React における自律的なデータ取得について
quramy
11
3k
大公開!iOS開発の悩みトップ5 〜iOSDC Japan 2024〜
ryunakayama
0
190
2024 컴포즈 정원사
jisungbin
0
150
Rubyのobject_id
qnighy
6
1.3k
RAGの回答精度評価用のQAデータセットを生成AIに作らせた話
kurahara
0
250
意外とフォントが大事だった話 / Font Issues on Internationalization
fumi23
0
110
How to Break into Reading Open Source
kaspth
2
210
AndroidアプリのUIバリエーションをあの手この手で確認する / Check UI variations of Android apps by various means
tkmnzm
1
170
Amebaチョイス立ち上げの裏側 ~依存システムとの闘い~
daichi_igarashi
0
230
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
460
Increased Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
350
Go1.23で入った errorsパッケージの小さなアプデ
kuro_kurorrr
2
390
Featured
See All Featured
Music & Morning Musume
bryan
46
6k
What's new in Ruby 2.0
geeforr
340
31k
A Philosophy of Restraint
colly
202
16k
Six Lessons from altMBA
skipperchong
26
3.4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
25
3.9k
Scaling GitHub
holman
458
140k
Docker and Python
trallard
39
3k
Unsuck your backbone
ammeep
667
57k
Imperfection Machines: The Place of Print at Facebook
scottboms
263
13k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
227
52k
The Invisible Side of Design
smashingmag
295
50k
Stop Working from a Prison Cell
hatefulcrawdad
267
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