SwiftUI Data & ArchitectureLesson 56Free preview
MVVM Architecture
This lesson is part of Swift · All levels
Summary
This lesson discusses the application of the Model-View-ViewModel (MVVM) architecture pattern which is the de facto standard in the development of SwiftUI applications. This pattern separates pure data structure (Model), declarative interface (View), and business logic as well as data transformation (ViewModel), so that code is easy to test and maintain.
Key points
- Models represent the structure of pure data entities (usually Struct and Codable)
- View is tasked with displaying the interface and listening to ViewModel data changes
- ViewModel adopts the 'ObservableObject' protocol and exposes the data with '@Published'
- Separate business logic from view so that it facilitates the creation of Unit Testing
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.