What is MVVM and how the hell does it work?

Federica Benacquista
5 min readMar 26, 2023

As soon as I started learning SwiftUI, I just focused on how to build nice views and all of the stuff that brings all the newbies and us, ruined by life-constraints-UIKit developers to SwiftUI. First impression? Nice! But how do I deal with real world problems now?
It popped to my head that I knew pretty much nothing about MVVM → impossible to create real apps. But now I kind of do. I’m not an expert (yet) but I make it all work smoothly so hopefully you will too after today.

MVVM representation

MVVM

MVVM stands for Model View View-Model.
The way I see it, the main focus of this pattern is the View-Model, as we should already be familiar with the model and the view. Anyway for those of you who aren’t, don’t worry: I explained below what they are and you’ll agree with me they’re not a big deal after all.

Model:

The model contains the data and the logic of the app, describing how it will behave. It’s the skeleton, it doesn’t have to know about the view. Therefore, we won’t import SwiftUI in the model files.

Example:
Imagine we have a random game where we need to define a player. The model of the app would have a Player struct containing the player data (name, points, level, exp) and some functions we can use on that player…

--

--

Federica Benacquista

I’m a self taught iOS developer and soon to be entrepreneur. I like to explain tricky concepts as easily as possible and it’s exactly what I do here.