IOS TOPICS

IOS Introduction
Swift UI Label
Swift UI Button
Swift UI Text Field
Swift UI Slider
Swift UI Switch
Swift UI Stepper
Swift UI Date Picker
Swift UI Segmented Control
Views
Table View
Collection Views
SCROLL VIEW
iOS Content View
iOS View Controllers
iOS Bar interface
iOS Navigation interface
iOS Architect Pattern
iOS Libraries
iOS Web request and parsing
iOS user defaults
iOS Coredata and database

Model View View-Model


Model View View-Model

An iOS architectural design pattern called MVVM (Model View View-Model) breaks items into three basic components.

  • Model: The application data is stored in this model; They are in charge of data parsing and data persistence, among other things.
  • View: including visual components and controls are shown on the screen via View. There are many ways to use it because it is a subclass of the more popular UIView.
  • ViewModel: the business logic translates the model data into values and sends them to the user interface (UI). The ViewModel handles every aspect of business logic in MVVM.

A new component, ViewModel, is added to the MVC design pattern, allowing the view controller's responsibility to be simplified and the business logic to be handled by the ViewModel instead of the view controller.

Where to use MVVM

As an alternative to MVC's hefty controller, MVVM provides a solution. It adds a fourth component, called ViewModel, to the system. For data manipulation activities, a ViewModel is responsible, and it manages the model by transferring its data to the view controller. Wherever we need to change models into a different representation for a view, this approach can be applied. A date object, for example, can be transformed into formatted text using the view model, as can a decimal number into formatted currency text. This design works well with MVC. By introducing another component, the goal is to reduce the function of a view controller. It is still necessary to have outlets and inject the formatted data into the view controller.