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

Common iOS architectures: From MVC to VIPER, wi...

Nelson
September 21, 2019

Common iOS architectures: From MVC to VIPER, with Redux

Common iOS Architecture: From MVC to VIPER, with Redux @ iPlayground 2019

這幾年大家逐漸重視 iOS 的架構設計,從最基本的 MVC 到開始普及的 MVP / MVVM,到分工細膩的 VIPER,每個 pattern 都有擁護者;近期也有為了解決畫面轉換的 Router / Coordinator 以及為了解決資料一致性的 Redux。

讓我們來聊聊這幾種 pattern 及其演化過程。

文字稿這裡
https://chiahsien.github.io/post/common-ios-architecture-from-mvc-to-viper-with-redux/

Nelson

September 21, 2019
Tweet

Other Decks in Programming

Transcript

  1. Who am I • App developer since iOS 4 •

    Years of working experience in startups • ! @nelsont • ! chiahsien.github.io
  2. MVC

  3. Model View Controller Data structure UI Life cycle Data manipulation

    Setup view & animation UI Navigation API call & biz logic Data conversion Data source & Delegate etc.
  4. Deal with Massive VC • VC focus on UI related

    tasks • Move non-UI related tasks to another object • VC communicate with this object
  5. Presenter / View Model • API call • Biz logic

    • Data conversion • Data source
  6. Model View VM / Presenter Data structure UI API call

    Data manipulation Life cycle Biz logic Setup view & animation Data conversion UI Navigation Data source Delegate etc.
  7. Problem • Hard to reuse • Lack of flexibility •

    Hard to co-work • Doesn’t make sense
  8. Solution • Each VC should be independent • An object

    having bird’s view manages VCs’ flow
  9. Model View VM / Presenter Coordinator Data structure UI API

    call UI Navigation Data manipulation Life cycle Biz logic Setup view & animation Data conversion Delegate Data source etc.
  10. Model View Presenter Coordinator Manager / Service Data structure UI

    Data conversion UI Navigation API call Life cycle Data source Biz logic Setup view & animation Data manipulation Delegate etc.
  11. Entity View Presenter Coordinator Manager / Service Data structure UI

    Data conversion UI Navigation API call Life cycle Data source Biz logic Setup view & animation Data manipulation Delegate etc.
  12. Entity View Presenter Router Manager / Service Data structure UI

    Data conversion UI Navigation API call Life cycle Data source Biz logic Setup view & animation Data manipulation Delegate etc.
  13. Entity View Presenter Router Interactor Data structure UI Data conversion

    UI Navigation API call Life cycle Data source Biz logic Setup view & animation Data manipulation Delegate etc.
  14. State management • MV(C/VM/P) / VIPER are UI related patterns

    • We need to find a way to manage state
  15. Redux •A state management framework •Single source of truth •Single

    place to modify state •Unidirectional data flow
  16. Redux integration • Presenter / Interactor send Actions to Store

    • Presenter / Interactor receive State update notification
  17. Summary • A series of refactoring • Find a pattern

    that suit your team • Both VM & Presenter are great • Recommend Coordinator for beginner • Manage state with care