Learning Time : 1h 15min
My Github : Bucket List Source Code
My Note index link

KeyWords
- MVVM
- ViewModel
- ObservableObject
- @MainActor
- documentDirectory
- LocalAuthentication
- Permissions
- Task & @MainActor
- Simulator test
Introducing MVVM into your SwiftUI project
- MVVM (Model View View-Model) architecture, a design pattern essential for structuring SwiftUI projects effectively.
- MVVM allows you to separate your data management and logic from your user interface, enhancing maintainability and testability.
Create ViewModel Class
- Create a new Swift file called
ContentView-ViewModel.swift
.
- Place the
ViewModel
class inside an extension
on ContentView.
- Define a class conforming to the
ObservableObject
protocol.
- Add the
@MainActor
attribute to the ViewModel class, ensuring all code within the class runs on the main actor. This is essential for safe UI updates.