Breaking Free from MVC: How MVVM Transformed Our iOS Development at Eventogy

Today, I’m specifically referring to our mobile Attendee and Host Apps and I’d like to share a significant shift we made in our development approach: transitioning from the Model-View-Controller (MVC) architecture to the Model-View-ViewModel (MVVM) architecture for our Swift iOS projects. This decision wasn’t made lightly, and I believe our journey can provide valuable insights for other developers considering the same path.
The limitations of MVC
MVC has been the go-to architecture for iOS development for years. It separates the application into three interconnected components: Model, View, and Controller. While this separation is conceptually sound, in practice, it often leads to some significant challenges:
- Massive View Controllers: As projects grow, view controllers tend to accumulate more responsibilities, becoming difficult to manage and test. Our Attendee and Host apps were no exceptions. The complexity in view controllers was leading to harder maintenance and slower development cycles.
- Testing difficulties: With so much logic tied up in view controllers, unit testing became cumbersome. The tight coupling between the UI and business logic made it challenging to test components in isolation.
- Poor code reusability: The MVC pattern often results in code that is tightly coupled, making it difficult to reuse components across different parts of the application.
Why MVVM?
The MVVM architecture addresses many of the shortcomings of MVC by introducing a ViewModel layer that handles the presentation logic and state management. Here are some key benefits we experienced:
- Improved separation of concerns: By moving presentation logic to the ViewModel, our view controllers became much leaner. This clear separation made our codebase more manageable and readable.
- Enhanced testability: With most of the logic residing in the ViewModel, we could write more effective unit tests. This improved our confidence in the code and reduced the occurrence of bugs.
- Better code reusability: MVVM promotes a more modular approach, allowing us to reuse ViewModels across different views. This was particularly beneficial in our attendee and host apps, where certain functionalities overlap.
Real-world examples and results
Both our attendee and host apps have seen significant improvements since adopting MVVM. Here are some examples of changes we implemented, along with the measurable results:
- Data handling: Initially, view controllers were responsible for data fetching, formatting, and UI updates. By shifting these responsibilities to ViewModels, we simplified our view controllers, making them more focused on presenting the UI. This change reduced our view controller code by approximately 40%.
- Real-time updates: Managing real-time data updates and UI refreshes in view controllers was challenging. With MVVM, this logic now resides in ViewModels, resulting in more responsive and maintainable code. This refactor improved our apps’ responsiveness and allowed for better isolation of real-time data handling, which contributed to a 25% reduction in development times for new features.
- Code reusability: Many functionalities in our apps overlap. MVVM allowed us to reuse ViewModels across different views, improving our development efficiency and reducing redundant code. This modular approach increased our unit test coverage by 30%, as ViewModels are easier to test in isolation.
Conclusion
Switching from MVC to MVVM has been a game-changer for our iOS projects at Eventogy. It has made our codebase more maintainable, our apps more reliable, and our development process more efficient. For any iOS developers struggling with massive view controllers and poor testability, we highly recommend considering MVVM. The transition might require an initial learning curve, but the long-term benefits are well worth the effort.
If you have any questions or need further insights into our MVVM journey, feel free to reach out. Let’s continue to build better, more maintainable apps together.
Happy coding!