From Past to Future: Changes in iOS ViewModel and Architecture Patterns

Ryoichi Izumita
5 min readOct 8, 2023

--

1. Introduction

The architecture of application development has been constantly changing in accordance with the evolution of technology and the needs of the industry. Especially in iOS applications, there has been a significant shift from the initial MVC-based design to modern declarative UI construction. At the center of this lies the existence of the ‘ViewModel’.

In this article, we explore the role of the ViewModel in iOS architecture and its evolution. In particular, we focus on its relationship with Apple’s MVC, traditional MVVM, and newly introduced frameworks such as SwiftUI and Flutter. Furthermore, we will look in detail at how these technologies and architectures interact and the impact they have had on the design and implementation of applications.

“From Past to Future: Changes in iOS ViewModel and Architecture Patterns”. Based on this theme, we will discuss the history and future possibilities of iOS app development, and the ideas and challenges behind it.

2. Differences between Traditional MVC and Apple’s MVC

The MVC (Model-View-Controller) pattern has long been used as an application architecture. How this MVC is interpreted and implemented varies depending on the background of the platform and technology.

The generally understood MVC takes the form where the View directly observes the Model. When a change occurs in the Model, the View detects this and updates itself. On the other hand, in the MVC proposed by Apple, there is one change in this structure. Specifically, the Controller is positioned between the Model and the View, and the exchange of data is done through the Controller, without the View directly observing the Model.

This difference is due to the characteristics of the development process and the iOS UI framework. In Apple’s MVC, the Controller, especially `UIViewController`, has many roles, and it can be said that it is close to the role of ViewModel as traditionally understood.

3. The Intersection of UIViewController and Markup Languages: Exploring the Existence of ViewModel

The approach of defining the UI of an application with markup languages is observed in many development environments and frameworks. The clear benefits behind this approach include the separation of visual design from code, improved reusability, and ease of maintenance and management. However, it also comes with challenges such as managing dynamic UI states and integrating with data. To address these challenges, some sort of intermediary manager is indispensable.

In iOS application development, the `UIViewController` characteristically serves the role of this “intermediary manager”. Indeed, the `UIViewController` handles data processing, UI state management, and responses to user input, roles that are very similar to the ViewModel in traditional MVVM architecture. Particularly in the iOS development environment, the method of defining UI with markup tools such as XIB or Storyboard can be considered one of the reasons why `UIViewController` takes on a ViewModel-like role.

Furthermore, by combining markup languages and ViewModel, it is possible to achieve a clean separation between UI and business logic. The benefits of this separation include improved testability of the application, reusability of each component, and enhanced maintainability.

In conclusion, the adoption of markup languages and the ViewModel-like role of `UIViewController` can be said to be important elements in forming the modern architecture of iOS application development.

4. RxSwift, MVVM, and the Unique Aspects of iOS Development

In recent years, Reactive Programming and MVVM have become central topics in iOS app development. This shift towards the center is deeply connected with the relationship between markup languages and the existence of ViewModel-like entities. RxSwift, a Reactive Programming library, treats data flows and changes as observable sequences. This feature is particularly noted in combination with MVVM, as it effectively facilitates the collaboration between UI defined in markup and data.

However, introducing MVVM without fully understanding the context of iOS app development can lead to misunderstandings and inefficient implementations. Ignoring the unique fact that iOS’s `UIViewController` already plays a ViewModel-like role, and introducing ViewModel without considering its close relationship with markup languages, can unnecessarily increase the complexity of development.

The background of these misunderstandings includes the unique circumstances of iOS app development, the influence of markup languages, and a general lack of understanding of MVVM and Reactive Programming. In particular, the approach of directly applying the perception of MVVM from other platforms and environments to iOS, without considering the uniqueness of `UIViewController` and iOS architecture, is likely to lead to misunderstandings.

5. The Emergence of SwiftUI and Flutter: The Evolution of ViewModel’s Role

In recent years, new frameworks like SwiftUI and Flutter have emerged, bringing significant changes to front-end development architecture. These frameworks provide an opportunity to reevaluate the role of ViewModels.

SwiftUI’s Approach:

SwiftUI is a framework focused on declarative UI construction and offers powerful data and UI binding capabilities. Views written in the programming language can have states. However, there are limitations such as the inability to use view-specific Property Wrappers in the ViewModel. As a result, the traditional role of the ViewModel is diminishing.

Flutter’s Approach:

Flutter also focuses on declarative UI construction and has a mechanism for state management. However, Flutter does not have its own binding mechanism, so it cannot interact with a general ViewModel.

The Evolution of ViewModel’s Role:

A common feature of these frameworks is the ability of the UI to manage state. However, even if the ViewModel becomes unnecessary, the role that the ViewModel played has not disappeared. In fact, that role is distributed to other parts, such as the state management mechanisms specific to the framework or library.

The Importance of Understanding ViewModel’s Role:

Even when the concrete existence of a ViewModel is deemed unnecessary, understanding the underlying role and philosophy is extremely important. This is because requirements such as state management, data processing, and UI collaboration exist in any architecture or framework. Recognizing this role is helpful in managing the structure and data flow of an application, even in implementations that do not explicitly use a ViewModel.
With the evolution of technology and the emergence of new frameworks, traditional architectures and patterns should always be reevaluated. However, understanding basic roles and requirements holds unchanging value, regardless of the environment or trend.

6. Conclusion and Future Prospects

Through this article, we have deeply explored the architecture of iOS application development, especially the role and transition of MVVM. We have considered the ViewModel-like role that the traditional `UIViewController` played, the influence of markup languages, and the emergence of new frameworks such as SwiftUI and Flutter and their impact on ViewModel.

Summary:

- There are similarities and differences between Apple’s MVC and traditional MVVM, with `UIViewController` playing a wide range of roles.
- The introduction of markup languages has brought new challenges to managing UI and logic, and has created the need for a ViewModel-like role.
- The roles and necessity of ViewModel are being re-evaluated with the emergence of new frameworks, SwiftUI and Flutter.
- However, understanding the basic role and philosophy behind ViewModel retains its value, regardless of the framework or architecture adopted.

Future Prospects:

- Technology is always evolving, and new trends in frameworks, tools, and architectures will emerge. It is required to be flexible in responding to these changes, without forgetting the understanding of basic principles and roles.
- As SwiftUI and Flutter mature further, it is expected that best practices for state management and architecture will become clearer.
- Ultimately, the most important goal for developers remains unchanged: to pursue the appropriate architectural choices and implementation methods to improve the quality and user experience of the application.

--

--