Upgrade to Pro — share decks privately, control downloads, hide ads and more …

VIPER with アーキテクチャ選定 実践入門 / VIPER Architecture

C0c3e2b792a468590679e46b86e1784d?s=47 hirothings
January 21, 2020

VIPER with アーキテクチャ選定 実践入門 / VIPER Architecture

iOS Clean Architecture勉強会 sponsored by Sansan
https://connpass.com/event/158269/

の登壇スライドです。

C0c3e2b792a468590679e46b86e1784d?s=128

hirothings

January 21, 2020
Tweet

More Decks by hirothings

Other Decks in Programming

Transcript

  1. VIPER with ΞʔΩςΫνϟબఆ ࣮ફೖ໳ @hirothings

  2. Agenda • VIPERͱ͸ʁ • ͳ࣮ͥ຿ͷΞʔΩςΫνϟʹVIPERΛબΜͩͷ͔ • (͓·͚)Embedded Frameworkʹ͍ͭͯ • એ఻

    • ΞʔΩςΫνϟબఆʹ͍ͭͯ
  3. ࣗݾ঺հ • @hirothings (Objective-ͻΖC) • ݩϥʔϝϯ԰ళ௕ϓϩάϥϚʔ • ౬੾ΓΛ͜ͷ··͍͍ͯͯ͠ͷ͔ࢥ্ཱ͍ͪژ • ݱࡏiOSσϕϩούʔ

  4. VIPERͱ͸ʁ

  5. VIPERͱ͸ʁ • View • Interactor • Presenter • Entity •

    Router ֤ϨΠϠʔͷ಄จࣈͷ૊Έ߹ΘͤͰ VIPER ͱݺͼ·͢ɻ
  6. 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/
  7. VIPERͷϨΠϠʔ

  8. VIPERͷϨΠϠʔ: Entity • όϦϡʔΦϒδΣΫτ

  9. VIPERͷϨΠϠʔ: Interactor • PresenterͷϦΫΤετʹԠͯ͡ΞϓϦͷϢʔεέʔ ε͝ͱʹϏδωεϩδοΫΛ࣮ߦ͢Δ૚ • EntityΛ஌͍ͬͯΔ • Viewͷ͜ͱ͸஌Βͳ͍

  10. VIPERͷϨΠϠʔ: Presenter • Viewʹର͢ΔϓϨθϯςʔγϣϯϩδοΫΛ࣋ͭ૚ • ViewͱRouter, Interactorͷڮ౉͠తଘࡏ • View͔Βड͚औͬͨΠϕϯτΛ΋ͱʹ •

    InteractorʹϦΫΤετ • Routerʹը໘ભҠΛґཔ͢Δ • Interactor͔Βड͚औͬͨσʔλΛViewʹ౉͢
  11. VIPERͷϨΠϠʔ: Presenter • Viewʹର͢ΔϓϨθϯςʔγϣϯϩδοΫΛ࣋ͭ૚ • ViewͱRouter, Interactorͷڮ౉͠తଘࡏ • View͔Βड͚औͬͨΠϕϯτΛ΋ͱʹ •

    InteractorʹϦΫΤετ • Routerʹը໘ભҠΛґཔ͢Δ • Interactor͔Βड͚औͬͨσʔλΛViewʹ౉͢
  12. VIPERͷϨΠϠʔ: View • View, ViewController • ϓϨθϯςʔγϣϯϩδοΫ͸࣋ͨͳ͍

  13. VIPERͷϨΠϠʔ: Router • ը໘ભҠΛ؅ཧ͢Δ • ֤ϨΠϠʔͷΠϯελϯεΛੜ੒͠ɺը໘Λඳը͢ Δ(ґଘੑΛͻͱ·ͱΊʹղܾ͢Δ૚͸͜͜)

  14. ͳ࣮ͥ຿ͷΞʔΩςΫνϟʹ VIPERΛબΜͩͷ͔

  15. • ϧʔςΟϯά͕ͳ͘VCؒͰݸผʹը໘ભҠͤͯ͞ΔͨΊભҠͷϩ δοΫ͕ࢄΒ͹Δ • σʔλͷऔಘɾՃ޻͚ͩΛ͢Δ૚͕ͳ͍ • ݁ՌɺϓϨθϯςʔγϣϯϩδοΫͱσʔλʹؔ͢ΔϩδοΫ͕ ࠞࡏ͢Δ • ґଘੑΛͻͱ·ͱΊʹղܾ͢Δ૚͕ͳ͍

    • Α࣮ͬͯ૷͕ଐਓԽ͢Δ MVCɺMVVMΞʔΩςΫνϟͰΞ ϓϦΛ࡞ͬͯײͨ͡՝୊ ޻෉͠ͳ͍ͱ..
  16. બఆʹࢸͬͨܦҢ ੍໿ • ॳظϦϦʔεʹؒʹ߹ΘͤΔʹ͸ͦ͜·Ͱ͕࣌ؒͳ͍ લఏ৚݅ • σʔλόΠϯσΟϯάΛଟ༻͢Δ΄ͲͷΠϯλϥΫςΟϒͳ ΞϓϦͰ͸ͳ͍ • API͔ΒσʔλΛऔͬͯग़͚ͩ͢ͷΞϓϦ(ϩʔΧϧDB΋࢖༻

    ͠ͳ͍) • ։ൃϝϯόʔ2, 3ਓ • ԣల։͢ΔΞϓϦͷج൫ͱͯ͠ɺϨΠϠʔ͸͔ͬͪΓ͓ͯ͠ ͘ඞཁ͕͋ͬͨ
  17. બఆʹࢸͬͨܦҢ ઌͷ՝୊͸࢓૊ΈԽͯ͠ղܾ͍ͨ͠ ϨΠϠʔυΞʔΩςΫνϟͷબఆ.. VIPER͕ྑͦ͞͏ αϯϓϧΞϓϦΛ ࡞ͬͯ൑அ͠·ͨ͠

  18. ՝୊ͱιϦϡʔγϣϯ ࠓ·Ͱͷઃܭʹ๊͍ͨ՝୊ VIPERͷιϦϡʔγϣϯ ϧʔςΟϯά͕ͳ͍ Router͕୲อͯ͘͠ΕΔ ϓϨθϯςʔγϣϯϩδοΫͱσʔ λʹؔ͢ΔϩδοΫ͕ࠞࡏ Presenter, InteractorͰ໌֬ʹ෼཭͞Ε͍ͯΔ ґଘੑΛͻͱ·ͱΊʹղܾ͢Δ૚͕

    ͳ͍ Router͕ΠϯελϯεΛੜ੒͠ґଘੑΛ·ͱΊΔ ໾ׂΛ୲͍ͬͯΔ ଐਓԽ͢Δ ϨΠϠʔ͕໌֬ͳͨΊଐਓԽͮ͠Β͍
  19. VIPERʹ࣮ͯ͠ࡍΑ͔ͬͨ఺ Router૚ͷଘࡏ • ը໘ભҠͷίʔυΛView͔Β෼཭Ͱ͖Δ • ͋ΒΏΔը໘ભҠʹରԠ͕Մೳ(ex. Universal Links͔ΒͷભҠ) • ґଘੑΛͻͱ·ͱΊʹ͢Δ૚͕͋Δ

  20. Routerʹؔͯ͠ ΞϓϦέʔγϣϯ޲͚ΞʔΩςΫνϟͷVIPERͰClean Architecture ʹΞυΦϯ͞ΕͨϨΠϠʔͰ͕͢ɺ Routerʹ͍ͭͯৄ͘͠஌Γ͍ͨํ͸iOSઃܭຊͷApplication CoordinatorͱRouterͷষ͕ࢀߟʹͳΓ·͢ɻ IUUQTQFBLTDDCPPLTJ04@BSDIJUFDUVSF ࠷ߴ!

  21. VIPERʹ࣮ͯ͠ࡍΑ͔ͬͨ఺ ςετ͠΍͍࣮͢૷Λ”ޙԡ͠”ͯ͘͠ΕΔ • ֤ϨΠϠʔΛInterfaceͷΈͰґଘͤ͞ΔͨΊɺstub, spyʹมߋ ͠΍͍͢ • ओʹνΣοΩϯά(खಈςετͷίετ͕͔͔ΔՕॴ)ʹࣗಈςε τΛಋೖ •

    ॻ͖ͮΒ͍৔߹͸ίʔυʹ໰୊͕͋Δ ࢀߟ • ୯ମςετͷϋδϝ • https://speakerdeck.com/yokoyas000/dan-ti-tesutofalsehazime
  22. ςετͷྫ ※આ໌ͷͨΊ؆ུԽͯ͠·͢ Presenterͷςετˠ ɾίετେ ɾϏδωεϩδοΫ - ViewͷҰ؏ͨ͠ςε τ͕Մೳ Interactorͷςετ ɾίετখ

    ɾ୯ೖྗ / ग़ྗͷςετ
  23. ͞Βʹେن໛։ൃʹͳΔͱ͡Θ͡Θײ͡ΔϝϦοτ • Domain, Data૚ͱView૚Ͱ୲౰Λ෼͚ΒΕͨΓ͢Δ • ෆ֬ఆཁૉʹର͢ΔରԠָ͕ͳͷͰ݁Ռૣ͍ • APIͱซ૸Ͱ։ൃ͢Δͱ͖=>ελϒͰ੩తͳ࣮૷ • ViewΛ࡞Γ௚ͯ͠΋Өڹൣғখ

    VIPER(Clean Architecture)։ൃͰΑ͍఺
  24. +Embedded Framework ΋ରԠ • ΞϓϦέʔγϣϯͷϞδϡʔϧ෼ׂ • ୯ํ޲ʹ͔͠ࢀরͰ͖ͳ͍ͨΊૄ݁߹ͳ࣮૷͕ڧ੍Ͱ͖Δ Embedded Frameworkͱ͸ •

    ը໘ʹؔ࿈͢ΔϨΠϠʔͱؔ࿈͠ͳ͍ϨΠϠʔͰߏ੒Λ෼͚ͨ • ը໘ʹؔ࿈͠ͳ͍ϨΠϠʔΛผϞδϡʔϧʹ෼ׂ ෼ׂͷํ਑
  25. ਖ਼͘͠෼ׂ͢Δ͜ͱΑΓը໘୯ҐͰӨڹൣғ͕ࢹ ֮తʹ෼͔ΔDXΛ༏ઌ Scene • View • Presenter • Interactor •

    Router ը໘ʹؔ࿈͠ͳ͍ϨΠϠʔ • API Request • DataStore • Entity • Utility • Components (Button..etc) "QQ ผϞδϡʔϧ
  26. ਖ਼͘͠෼ׂ͢Δ͜ͱΑΓը໘୯ҐͰӨڹൣғ͕ࢹ ֮తʹ෼͔ΔDXΛ༏ઌ Scene • View • Presenter • Interactor •

    Router ը໘ʹؔ࿈͠ͳ͍ϨΠϠʔ • API Request • DataStore • Entity • Utility • Components (Button..etc) "QQ ผϞδϡʔϧ ඍົͳϥΠϯ͕ͩ རศੑʹدͤͨՕॴ
  27. ϑϧFirebaseͰݸਓΞϓϦ࡞Γ·ͨ͠

  28. ݸਓΞϓϦͷΞʔΩςΫνϟͳΜͰ͔͢ʁ

  29. ݸਓΞϓϦͷΞʔΩςΫνϟͳΜͰ͔͢ʁ MVCͰ͢㊙

  30. ΞʔΩςΫνϟͷબఆʹ͍ͭͯ૝͏͜ͱ

  31. ΞʔΩςΫνϟͷબఆʹ͍ͭͯ • ΞϓϦͷ੒௕ͱෳࡶ͞ʹΑͬͯऔΔ΂͖ख๏͕ม Θͬͯ͘Δ

  32. ΞʔΩςΫνϟͷબఆʹ͍ͭͯ ྫ) ചΕΔ͔෼͔Βͳ͍ݸਓΞϓϦ <։ൃ؀ڥ> ɾ1ਓ <ΞϓϦͷෳࡶੑ> ɾγϯϓϧ(͡Όͳ͍ͱϠό͍) <ऩӹ> ɾZERO ചΕΔ͔Ͳ͏͔෼͔Βͳ͍ΞϓϦʹ͍ͨͦ͏ͳ

    ΞʔΩςΫνϟ͸ෆཁ
  33. ΞʔΩςΫνϟͷબఆʹ͍ͭͯ ΞϓϦͷ੒௕ʹ߹ΘͤͯΞϓϦͷػೳɾ։ൃ؀ ڥͷෳࡶੑ͕૿͢ "1*ϦΫΤετ ։ൃϝϯόʔ"

  34. ΞʔΩςΫνϟͷબఆʹ͍ͭͯ "1*ϦΫΤετ ։ൃϝϯόʔ" ։ൃϝϯόʔ# ։ൃϝϯόʔ$ ϩʔΧϧ%#อଘ ଟݴޠల։ $* 2" $%

    ΞϓϦͷ੒௕ʹ߹ΘͤͯΞϓϦͷػೳɾ։ൃ؀ ڥͷෳࡶੑ͕૿͢
  35. ΞʔΩςΫνϟͷબఆʹ͍ͭͯ ෳ਺"1*ϦΫΤετ ։ൃϝϯόʔ" ։ൃϝϯόʔ# ։ൃϝϯόʔ$ ϩʔΧϧ%#อଘ ଟݴޠల։ $* 2" $%

    ΞϓϦͷ੒௕ʹ߹ΘͤͯΞϓϦͷػೳɾ։ൃ؀ ڥͷෳࡶੑ͕૿͢ ։ൃϝϯόʔ% ίϯϑϦΫτ໰୊ $4ରԠ ύϑΥʔϚϯε໰୊ "#ςετ ίʔσΟϯάελΠϧ ͕όϥόϥ ΞϓϦԣల։ ։ൃϝϯόʔ&
  36. ΞʔΩςΫνϟͷબఆʹ͍ͭͯ ԿΛղܾ͍͔ͨ͠ʁ ͸ɺΞϓϦͷ੒௕ͱෳࡶੑʹΑͬͯมΘΔɻ ΞϓϦͷ੒௕ʹ߹ΘͤͨΞʔΩςΫνϟͷબఆɾվળ͕ॏཁɻ

  37. • View • Interactor • Presenter • Entity • Router

    ࣮ࡍͷϓϩδΣΫτͷվળࣄྫ
  38. • View • Interactor • Presenter • Entity • Router

    "1*͚ͩͰ͸ͳ͘ϩʔΧϧ͔ Β΋σʔλऔಘ͢Δ૚ΛϦ ϑΝΫλϦϯά ಉ͡&OUJUZͰ΋ը໘͝ͱʹද ࣔ͢Δ಺༰͕શવҧ͏ +Model +DataStore +Translator ࣮ࡍͷϓϩδΣΫτͷվળࣄྫ Ұ෦'MVYΛಋೖ ผҊ݅
  39. ΞϓϦͷ੒௕ʹ߹ΘͤͯঃʑʹϦϑΝΫλϦϯά͠ɺ ΞʔΩςΫνϟΛ͏·͘औΓೖΕ͍͖ͯ·͠ΐ͏ Fin