Mvvm
Generated on 8/3/2024
3 searches
The Model-View-ViewModel (MVVM) pattern is a common architectural pattern used in SwiftUI to manage the state and behavior of views. SwiftUI's declarative syntax and state management features align well with the principles of MVVM.
Key Concepts in SwiftUI Related to MVVM
-
State Management:
- SwiftUI views are state-driven. When the state changes, SwiftUI automatically updates the UI. This is similar to how the ViewModel in MVVM updates the View when the Model changes.
- Example: Using
@State
to manage internal state and@Binding
for two-way data binding between views. - SwiftUI essentials (08:50)
-
View Composition:
- SwiftUI allows for the composition of views, which can be used to build complex UIs from smaller, reusable components. This aligns with the MVVM principle of separating the UI (View) from the business logic (ViewModel).
- Example: Using custom views within a
List
and applying view modifiers for customization. - SwiftUI essentials (07:55)
-
Bindings and Single Source of Truth:
- SwiftUI's
@Binding
property wrapper allows for a single source of truth, ensuring that the state is consistent across different parts of the UI. - Example: Using
@Binding
to synchronize state between a container view and its child views. - SwiftUI essentials (12:29)
- SwiftUI's
Relevant Sessions
- SwiftUI essentials:
- Fundamentals of views: Discusses state-driven views and how SwiftUI manages state changes.
- Built-in capability: Explores built-in features and how to leverage them for complex UI compositions.
For more detailed information, you can refer to the SwiftUI essentials session from WWDC 2024.
Catch up on accessibility in SwiftUI
SwiftUI makes it easy to build amazing experiences that are accessible to everyone. We’ll discover how assistive technologies understand and navigate your app through the rich accessibility elements provided by SwiftUI. We’ll also discuss how you can further customize these experiences by providing more information about your app’s content and interactions by using accessibility modifiers.
Migrate your TVML app to SwiftUI
SwiftUI helps you build great apps on all Apple platforms and is the preferred toolkit for bringing your content into the living room with tvOS 18. Learn how to use SwiftUI to create familiar layouts and controls from TVMLKit, and get tips and best practices.
SwiftUI essentials
Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.
Explore multiview video playback in visionOS
Learn how AVExperienceController can enable playback of multiple videos on Apple Vision Pro. Review best practices for adoption and explore great use cases, like viewing a sports broadcast from different angles or watching multiple games simultaneously. And discover how to design a compelling and intuitive multiview experience in your app.