ios architecture
TRANSCRIPT
iOS Architecture Essential
Jiakai(Jacky) Lian Mobile Developer @ GoGet
About Me❖ Focus on mobile development
since the era of 2G❖ Master of Applied IT @ Monash❖ Not a full stack developer❖ Focus on iOS in recent 2 years❖ Recently Joined GoGet
CarSharing❖ LinkedIn:
https://au.linkedin.com/in/jacky-lian-06493379
❖ GitHub: https://github.com/jiakai-lian/
Purpose of Architecture Design
❖ Resolve real business problems❖ Remove unnecessary dependencies❖ Reduce maintenance cost❖ Prepare for changes
3 Main Roles in Architecture
❖ Data Owner❖ Data Processor❖ Data Consumer
Everything starts from MVC
❖ MVC: Model+View+Controller
❖ MVC in Web programming❖ View Container: Web
Browser❖ Model: Model Layer
What Apple promised
The Reality
❖ MVC = Massive View Controller❖ View Controllers have too many responsibilities: Networking, Data
Access,UI configuration, Data Source, Delegate …❖ Shared Data causes problems (Mutability Management)❖ Controllers are the least reusable classes in the project❖ “Cocoa MVC is the best architectural pattern in terms of the speed of
the development.”
Slim Model V.S. Fat Model
❖ Fat Model❖ Business Logic in Model
❖ Slim Model❖ Model + Helpers❖ MVC-S: MVC+Data Store(Data Access)❖ MVC-N: MVC+Networking
The True MVC in Mobile: MVP
❖ MVP: Model+Passive View+Presenter❖ All UI logic in presenter.❖ View knows nothing about Model
MVVM
❖ MVVM = Model+View+ViewModel❖ ViewModel Definition
MVVM:View Model
❖ Non-Pattern ViewModel: ViewData/Transition Data (Immutable)
❖ ViewModel in MVVM: Independent Presentation Logic
MVVM: Where is the Controller
❖ MVVM = M-VM-C-V = Model ViewModel Controller View❖ Controller bind View and ViewModel together
Benefits of ViewModel
❖ No direct dependency between Model & View❖ UI Independent Presentation Logic
MVVM With Binding
❖ Fine without binding ❖ Even better with binding❖ Popular Binding Frameworks:
ReactiveCocoa(ObjC & Swift), RxSwift❖ Reactive : Learning Cost ⬆ ❖ Binding: Debugging Difficulty⬆
VIPER
❖ VIPER = View+Interactor+Presenter+Entity+Router❖ Interactor: Business Logic, using external data access
layer❖ Presenter: UI related (but UIKit independent) business
logic❖ Entities: Slim Model (Plain Data Objects)❖ Router: Routing between different modules
VIPER: Highlights
❖ Evenly distribute responsibilities❖ UseCase focused❖ Able to combine different UI protocols to build up a screen
VIPER: Problems
❖ Too many classes: Development/Maintenance Cost ⬆❖ Too complex for simple apps: Slow down the development
VIPER: Suggestions
❖ Workload Reduce: Use Script/Template to generate all those classes
❖ Not a practical choice for s/m projects❖ A option for large projects (Team Size ≈ 5/Development
Life Cycle ≥ 6 month)
Ziggurat❖ Created by Square❖ Inspired by React Native & Flux
Ziggurat❖ More layers distribute
responsibility evenly❖ The service layer
encapsulates mutability❖ Presenter & Renders are
stateless❖ One Way Data Flow❖ Repository = Data Store❖ View Model = View Data❖ Drawback: Relatively
hard to manage animations
Rules Of Thumb❖ Dependency is the No.1 concern❖ More layers = Less coupling = Harder to
understand❖ No right or wrong architecture❖ Plan well then improve your architecture
iteratively
Massive Class Prevention
❖ No more than 300 lines of code
Future Topics
❖ Architecture Design By Practice❖ Protocol Oriented Design in Swift❖ iOS Animation Design By A Live Example/Examples
References❖ http://casatwy.com/iosying-yong-jia-gou-tan-viewceng-de-zu-zhi-he-diao-yong
-fang-an.html❖ https://www.objc.io/issues/13-architecture/viper/❖ https://www.objc.io/issues/13-architecture/mvvm/❖ https://medium.com/ios-os-x-development/ios-architecture-patterns-ecba4c3
8de52#.tlnbspmx8❖ https://www.raywenderlich.com/62699/reactivecocoa-tutorial-pt1❖ https://www.youtube.com/watch?v=4cP1p5VOrSI❖ https://corner.squareup.com/2015/12/ziggurat-ios-app-architecture.html❖ http://khanlou.com/2015/12/mvvm-is-not-very-good/❖ http://limboy.me/ios/2015/09/27/ios-mvvm-without-reactivecocoa.html