Are viewmodels recommended

Asked on 06/11/2025

1 search

Yes, viewmodels are recommended in SwiftUI to optimize performance by making data dependencies more granular. In the session Optimize SwiftUI performance with Instruments, it is explained that by creating an observable viewmodel for each view, you can track specific data changes, such as a favorite status, more efficiently. This approach reduces unnecessary view body updates, as each view only depends on its own viewmodel rather than a larger data structure. This helps in keeping the app running smoothly by ensuring that only the necessary view bodies are updated when data changes.