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
900
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.1k
Swift2年生
hirothings
4
33k
Swiftへの愛
hirothings
0
34k
Other Decks in Programming
See All in Programming
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
330
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
go.mod、DockerfileやCI設定に分散しがちなGoのバージョンをまとめて管理する / Go Connect #3
arthur1
10
2.3k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
1
290
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
540
Why Spring Matters to Jakarta EE - and Vice Versa
ivargrimstad
0
960
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
360
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.7k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.1k
Kotlin2でdataクラスの copyメソッドを禁止する/Data class copy function to have the same visibility as constructor
eichisanden
1
130
Featured
See All Featured
A Tale of Four Properties
chriscoyier
156
23k
For a Future-Friendly Web
brad_frost
175
9.4k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
13
1.9k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Facilitating Awesome Meetings
lara
49
6k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Writing Fast Ruby
sferik
626
61k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
How to Ace a Technical Interview
jacobian
275
23k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.1k
Testing 201, or: Great Expectations
jmmastey
38
7k
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