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

iOSアプリのアーキテクチャについて考える

 iOSアプリのアーキテクチャについて考える

MVC, MVVM, ReactorKitで構築できるThe Reactive Architecture(Reactive Programming + Flux)について

iPhone Dev Sapporo勉強会 May, 2017
https://devsap.connpass.com/event/56182/

次: ReactorKitを実戦投入してみて
https://speakerdeck.com/yusuga/reactorkitwoshi-zhan-tou-ru-sitemite

Yu Sugawara

May 20, 2017
Tweet

More Decks by Yu Sugawara

Other Decks in Technology

Transcript

  1. ୅දతͳΞʔΩςΫνϟ 4 MVC 4 MVC2 / Model 2 (MVC) Architecture

    4 AppleͷϑϨʔϜϫʔΫͰ࠾༻͞Ε͍ͯΔ 4 MVP 4 MVVM 4 Clean Architecture
  2. Massive View Controllerͱ͸ 4 ControllerͰ༷ʑͳॲཧΛߦ͏͜ͱʹͳΓڊେԽͨ͠ঢ়ଶ 4 Viewͷੜ੒΍؅ཧ 4 I/Oॲཧ 4

    σʔλͷม׵ 4 ΩʔϘʔυͷ؅ཧ 4 DelegateͳͲͰҠৡ͞Εͨॲཧ 4 ը໘ભҠ
  3. Massive View ControllerͷݪҼͱվળ 4 ༷ʑͳϏδωεϩδοΫΛControllerʹॻ͖͕ͪ 4 ϏδωεϩδοΫ == ॲཧ 4

    ͨͩ͢͠΂ͯͷॲཧͰ͸ͳ͍ 4 ControllerͰ΍Δ΂͖ॲཧ΋͋Δ 4 جຊ͸Ϟσϧ͕ϏδωεϩδοΫΛߦ͏
  4. Massive View ControllerͷݪҼͱվળ 4 ༷ʑͳϏδωεϩδοΫΛControllerʹॻ͖͕ͪ 4 ϏδωεϩδοΫ == ॲཧ 4

    ͨͩ͢͠΂ͯͷॲཧͰ͸ͳ͍ 4 ControllerͰ΍Δ΂͖ॲཧ΋͋Δ 4 جຊ͸Ϟσϧ͕ϏδωεϩδοΫΛߦ͏ 4 ߏ଄Խ/ந৅Խ͔͗ͯ͑ͬͯ͢͠ಡΈͮΒ͘ͳΔ৔߹΋
  5. Massive View ControllerͷݪҼͱվળ 4 ༷ʑͳϏδωεϩδοΫΛControllerʹॻ͖͕ͪ 4 ϏδωεϩδοΫ == ॲཧ 4

    ͨͩ͢͠΂ͯͷॲཧͰ͸ͳ͍ 4 ControllerͰ΍Δ΂͖ॲཧ΋͋Δ 4 جຊ͸Ϟσϧ͕ϏδωεϩδοΫΛߦ͏ 4 ߏ଄Խ/ந৅Խ͔͗ͯ͑ͬͯ͢͠ಡΈͮΒ͘ͳΔ৔߹΋ 4 ϥϏΦϦίʔυ
  6. query.rx_text // 1. 3จࣈҎ্ .filter {string in return string.characters.count >

    3 } // 2. ࠷ޙͷೖྗ͔Β0.51ඵܦա .debounce(0.51, scheduler: MainScheduler.instance) // 3. ϦΫΤετΛੜ੒ .map {string in let apiURL = NSURL(string: "https://api.github.com/q?=" + string)! return NSURLRequest(URL: apiURL) } // 4. ϦΫΤετΛ࣮ߦʢඇಉظ௨৴ʣ .flatMapLatest { request in return NSURLSession.sharedSession().rx_data(request) } // 5. ϦΫΤετ݁ՌΛJSONΦϒδΣΫτʹม׵ .map { data —> Array<AnyObject> in let json = try NSJSONSerialization.JSONObjectWithData( data, options: []) return json as! Array<AnyObject> } // 6. RepoΦϒδΣΫτʹม׵ .map {object in return Repo(object: object) } // 7. RepoΦϒδΣΫτΛTableViewʹ൓ө .bindTo(tableView.rx_itemsWithCellIdentifier("Cell")) iOSΞϓϦ։ൃʹ͓͚ΔRxSwiftͷ׆༻ (※ ίʔυ͸rxswift-2.0)
  7. iOSͰReactive Programming 4 ReactiveCocoa ⭐ 17,222 4 Objective-C࣌୅͔Β͋Δݹג 4 RxSwift

    ⭐ 9,244 4 ReactiveX(Reactive Extensions)ϑΝϛϦʔ 4 Rx.NET͔Β࢝·Γ༷ʑͳݴޠʹҠ২
  8. iOSͰReactive Programming 4 ReactiveCocoa ⭐ 17,222 4 Objective-C࣌୅͔Β͋Δݹג 4 RxSwift

    ⭐ 9,244 4 ReactiveX(Reactive Extensions)ϑΝϛϦʔ 4 Rx.NET͔Β࢝·Γ༷ʑͳݴޠʹҠ২ 4 ଞͷRxJava, RxJSͳͲͱ֓೦͕౷Ұ͞Ε͍ͯΔͷͰ Web্ͷ৘ใ͕๛෋
  9. iOSͰReactive Programming 4 ReactiveCocoa ⭐ 17,222 4 Objective-C࣌୅͔Β͋Δݹג 4 RxSwift

    ⭐ 9,244 4 ReactiveX(Reactive Extensions)ϑΝϛϦʔ 4 Rx.NET͔Β࢝·Γ༷ʑͳݴޠʹҠ২ 4 ଞͷRxJava, RxJSͳͲͱ֓೦͕౷Ұ͞Ε͍ͯΔͷͰ Web্ͷ৘ใ͕๛෋
  10. ·͗ΒΘ໊͍͠শ 4 React (௨শ React.js/ReactJS) 4 Facebook੡ͷJavaScriptϥΠϒϥϦ 4 React Native

    4 ReactͰiOS/Android։ൃ͕Ͱ͖ΔFacebook੡ͷϑϨ ʔϜϫʔΫ 4 Reactive Programming 4 ඇಉظσʔλετϦʔϜΛ༻͍Δϓϩάϥϛϯάύϥμ
  11. MVVM 4 MicrosoftൃͷΞʔΩςΫνϟ 4 ίΞίϯηϓτ͸ɺσʔλόΠϯσ Οϯά 4 ViewModelͱ͍͏Modelͷσʔλ ΛViewͰѻ͍΍͘͢͢Δ΋ͷΛઃ ͚Δɻ

    4 ViewͱViewModelؒ͸σʔλόΠ ϯσΟϯάͱ͍͏ػೳΛ࢖͍ɺσ ʔλͦͷ΋ͷΛڞ༗ͯ͠औΓѻ͏ WebΞϓϦέʔγϣϯ։ൃऀ͔ΒݟͨɺMVCͱMVPɺͦͯ͠MVVMͷҧ͍
  12. Reactive Programming + MVVM 4 Massive View Controller͸վળ͞Εͨɻ 4 ...͔͠͠ɺ৽ͨʹผͷෳࡶ͕͞ൃੜͨ͠ɻ

    4 ControllerͰߦͳ͍ͬͯͨॲཧ͕ViewModelʹҠΓɺ ͦΕͰMasassive View Controller͕վળ͞Ε͚ͨͩ
  13. Reactive Programming + MVVM 4 Massive View Controller͸վળ͞Εͨɻ 4 ...͔͠͠ɺ৽ͨʹผͷෳࡶ͕͞ൃੜͨ͠ɻ

    4 ControllerͰߦͳ͍ͬͯͨॲཧ͕ViewModelʹҠΓɺ ͦΕͰMasassive View Controller͕վળ͞Ε͚ͨͩ 4 ͜Ε͸ઃܭ͚ͩͰͲ͏ʹ͔Ͱ͖Δ໰୊͡Όͳ͍ͷͰ͠ΐ ͏͕ͳ͍
  14. Reactive Programming + MVVM 4 Massive View Controller͸վળ͞Εͨɻ 4 ...͔͠͠ɺ৽ͨʹผͷෳࡶ͕͞ൃੜͨ͠ɻ

    4 ControllerͰߦͳ͍ͬͯͨॲཧ͕ViewModelʹҠΓɺ ͦΕͰMasassive View Controller͕վળ͞Ε͚ͨͩ 4 ͜Ε͸ઃܭ͚ͩͰͲ͏ʹ͔Ͱ͖Δ໰୊͡Όͳ͍ͷͰ͠ΐ ͏͕ͳ͍ 4 Reactive ProgrammingͰίʔυྔ͸ݮΒͤΔ
  15. RxSwiftͷॴײ 4 ૒ํ޲όΠϯσΟϯά 4 ୯ํ޲όΠϯσΟϯάΛ͓ޓ͍ʹߦ͑͹૒ํ޲όΠϯσ ΟϯάͩΑͶ! - by RxSwiftͷIssueʹͯ 4

    ୯७ʹσʔλ͕ಉظ͞ΕΔΑ͏ͳ࢓૊ΈͰ͸ͳ͍ ReactiveX/RxSwift - two-way binding #152
  16. RxSwiftͷॴײ 4 ૒ํ޲όΠϯσΟϯά 4 ୯ํ޲όΠϯσΟϯάΛ͓ޓ͍ʹߦ͑͹૒ํ޲όΠϯσ ΟϯάͩΑͶ! - by RxSwiftͷIssueʹͯ 4

    ୯७ʹσʔλ͕ಉظ͞ΕΔΑ͏ͳ࢓૊ΈͰ͸ͳ͍ 4 ߏจ͸ॻ͖΍͘͢ɺDelegateɺClosureɺCocoaͷ KVOΑΓ͸ॊೈͰ࣮૷΋ָ ReactiveX/RxSwift - two-way binding #152
  17. ReactorKit 4 ։ൃऀ @devxoul 4 Then ⭐ 1,616 4 URLNavigator

    ⭐ 1,076 4 Toaster ⭐ 722 4 SwiftyImage ⭐ 612 4 UITextView+Placeholder ⭐ 572 4 RxKeyboard ⭐ 444
  18. Flux 4 Actions: View౳͔ΒൃՐ͞Εͯ࡞ ΒΕΔΠϕϯτ 4 Dispatcher: શͯͷΞΫγϣϯΛ ड͚ͯStoreʹΠϕϯτΛൃՐ͢Δ 4

    Stores: ΞϓϦέʔγϣϯશମͷ σʔλͱϏδωεϩδοΫ(ඞͣ ActionʹΑͬͯσʔλΛߋ৽͢Δ) Fluxͱ͸ͳΜͳͷ͔
  19. The Reactive Architecture 4 MVVMͷVM͕Reactorʹஔ͖׵ ͑ΒΕͨ 4 View͕ΞΫγϣϯΛग़ྗ͠ɺ Reactor͕ঢ়ଶ(State)Λग़ྗ͢Δ 4

    ୯ํ޲ͷσʔλϑϩʔ(Flux) 4 Reactor͸Reactive ProgrammingͰ୯ํ޲ͷσʔλε τϦʔϜΛߏங͍ͯ͠Δ https://github.com/ReactorKit/ReactorKit
  20. The Reactive ArchitectureͱMVVMͷൺֱ 4 The Reactive Architecture 4 RxTodo 4

    Reactive Programming + MVVM 4 RxTodo / mvvm branch
  21. ·ͱΊ 4 Reactive Programming (RxSwift) 4 ཁॴཁॴͷ։ൃޮ཰Ξοϓ 4 MVVM 4

    Massive View ControllerΛվળ 4 The Reactive Architecture (ReactorKit)
  22. ·ͱΊ 4 Reactive Programming (RxSwift) 4 ཁॴཁॴͷ։ൃޮ཰Ξοϓ 4 MVVM 4

    Massive View ControllerΛվળ 4 The Reactive Architecture (ReactorKit) 4 MVVMΛΑΓѻ͍΍͍͢ߏ଄ʹվળ
  23. ReactorKit 4 2017/5/20 v0.4.3 4 جຊઃܭ͸Ͱ͖͍ͯΔΑ͏ʹݟ͑Δ͕ɺ·ͩv1.0ʹୡ͠ ͍ͯͳ͍ 4 RxSwift +

    MVVMΑΓ͸؆୯͔ͩΒྲྀߦΔ͔ͳʁ 4 ݸਓతʹ͸޷͖ͳઃܭࢥ૝ 4 ڵຯ͕ଓ͍͍ͯͨΒɺ࣍ճͷษڧձͰReactorKitͷ࿩͕Ͱ ͖Ε͹ͱࢥ͍·͢ɻ
  24. ࢀߟ 4 Разбираем Massive View Controller 4 Massive View Controller

    4 8 Patterns to Help You Destroy Massive View Controller 4 Let's Play: ڊେϏϡʔίϯτϩʔϥΛϦϑΝΫλϦϯά͠ Α͏ʂ 4 iOSΞϓϦ։ൃʹ͓͚ΔRxSwiftͷ׆༻ 4 React͸ϦΞΫςΟϒϓϩάϥϛϯάͳͷ͔?