Shall I use ViewModels?
Asked on 06/11/2025
1 search
Using ViewModels can be beneficial for optimizing SwiftUI performance, especially when you want to make your views' data dependencies more granular. In the session Optimize SwiftUI performance with Instruments, it is demonstrated how creating an observable ViewModel for each view can help reduce unnecessary view body updates. By having each view depend directly on its own ViewModel rather than a larger data structure, you can ensure that only the necessary views are updated when data changes. This approach can help keep your app running smoothly by minimizing the number of updates and improving performance.

Optimize SwiftUI performance with Instruments
Discover the new SwiftUI instrument. We’ll cover how SwiftUI updates views, how changes in your app’s data affect those updates, and how the new instrument helps you visualize those causes and effects. To get the most out of this session, we recommend being familiar with writing apps in SwiftUI.

Code-along: Elevate an app with Swift concurrency
Learn how to optimize your app’s user experience with Swift concurrency as we update an existing sample app. We’ll start with a main-actor app, then gradually introduce asynchronous code as we need to. We’ll use tasks to optimize code running on the main actor, and discover how to parallelize code by offloading work to the background. We’ll explore what data-race safety provides, and work through interpreting and fixing data-race safety errors. Finally, we’ll show how you can make the most out of structured concurrency in the context of an app.

Code-along: Bring on-device AI to your app using the Foundation Models framework
Develop generative AI features for your SwiftUI apps using the Foundation Models framework. Get started by applying the basics of the framework to create an awesome feature. Watch step-by-step examples of how to complement the models with tools you build, stream results, and apply further optimizations for great performance.