πPre-lecture Reading II
SP 2026 | Jay Zheng
What is MVC?
MVC stands for Model-View-Controller. It's a software design pattern β a set of rules that govern how we organize our code. UIKit apps follow MVC as their core architecture.
Think of it like a TV setup as an analogy:
Model
TV channels
Where the actual data lives
View
TV screen
Displays what's happening right now
Controller
Remote control
Tells the system what to do based on user input

Key Rule: Views and Models never talk to each other directly. They always communicate through the Controller.
Model
Models are objects that represent your app's data. They hold the information your app works with and get updated based on user interaction or data from a backend.
Example: In Eatery, the models are things like dining halls and food items.
We typically define models as structs in Swift.
Quick refresher on Structs vs Classes
Structs are value types. When you assign a struct to a new variable or mutate it, Swift creates a copy. The original is untouched.
swift
Classes are reference types. Multiple variables can point to the same object in memory. Changing one affects all references.
swift
When to use which? Use structs for simple data models β they're faster and safer since mutations don't have unintended side effects. Use classes when you need inheritance or shared mutable state (like UIViewController).
View
Views are the visible UI components β everything the user sees and interacts with.
This includes UILabel, UIButton, UIImageView, and so on, all of these are its own view!
In Eatery, the dining hall name displayed on screen is a UILabel that pulls its text from a dining hall model.
Controller
Controllers are the glue between models and views. In UIKit, the controller is a UIViewController.
A typical flow:
User taps a
UIButton(a view)The controller receives that tap event
The controller updates the model (e.g., adds an item)
The controller updates the view to reflect the change
Navigation
So far you've been working with a single screen. But real apps have many screens, each represented by its own UIViewController.
There are two main ways to navigate between screens:
Pushing / Popping
View controllers are pushed onto and popped off of a navigation stack.
The stack is managed by a
UINavigationController(typically set up inSceneDelegate.swift).
Imagine a screen of information
Pushing - slides a new screen in from the right.
Popping - removes it

Presenting / Dismissing
A view controller is presented on top of the current one (like a modal/sheet).
It can be dismissed via gestures like swiping down or tapping a close button.

Delegation (Preview)
Delegation is a pattern that lets a child view controller communicate back to its parent. For example, a settings screen might need to tell the home screen that the user changed their name.
The key idea: the child VC doesn't know which specific parent it's talking to β it just knows the parent can do certain things, defined by a protocol. This keeps things loosely coupled.
Key terminology:
Delegator = the child VC that asks someone else to do something
Delegate = the parent VC that actually does the work
Protocol = the contract between them (similar to interfaces in Java)
We'll dive much deeper into delegation and protocols in a future lecture. For now, just understand the high-level flow: child says "hey delegate, something happened" β parent handles it.
Key Takeaways
MVC separates your code into data (Model), UI (View), and logic (Controller). Views and models communicate only through the controller.
Structs copy on assignment (value type). Classes share references (reference type). Prefer structs for data models.
Navigation uses pushing/popping (with
UINavigationController) or presenting/dismissing to move between screens.Delegation uses protocols to let child VCs communicate back to parent VCs without tight coupling.
Last updated
Was this helpful?