MVVM Architecture For iOS Apps

Abhishek Kumar
2 min readAug 31, 2018

--

As an iOS developer we all have used MVC architecture. Apple also recommends to use it and it’s really popular architecure. But there is difference in how it pans out practically and how it should be in theory.

ViewController file become big and View logic and presentation becomes part of Controller. Due to use of Xib and StoryBoards (Inteface builders) View and Controller becomes tightly coupled.

MVC is now called as Massive View Controller in developer circles.

So, New version of MVC called MVVM architecture is becoming popular.

MVVM — Model — View — ViewModel

Let’s discuss each component responsiblities:

  • View — Presentation, user interaction.
  • ViewModel — Presentation logic.
  • Model — Business Logic

Pros: Solve Massive View Controller problem, Code re usability, and Code organization.

Cons: Requires binding, Overkills for simple views and logic (Don’t use MVVM for sake of using MVVM i.e. MVC can be better in some scenarios and MVVM can serve better in others).

iOS (Swift) doesnot support data binding like Android and Xamarin platforms do but it can be achieve using React Swift framework (RxSwift) which is having it’s own Variable and Observable mechanisms in which View can subscribe for any change in model.

Unfortunately Apple doesnot adopt MVVM pattern but as it becomes popular and easy to understand as compare to VIPER and Clean Architecture.

If still you chose to use MVC architecture, make use of extensions and enums for better separation of functionality.

--

--