is there any feature in lazyhstack in a scrollview that allows any pre-emptive onAppear. That way things can happen in this pre-emptive onAppear before it appears on screen?
Asked on 06/12/2025
•@wwdc251 search
In the context of SwiftUI and lazy stacks within a ScrollView
, there isn't a direct mention of a feature that allows for a pre-emptive onAppear
before a view appears on screen. However, SwiftUI does optimize the loading of views in lazy stacks by delaying the loading of contained views until they are about to appear, which helps in managing performance and responsiveness.
For handling tasks when a view appears, you can use the task
modifier in SwiftUI, which allows you to perform asynchronous operations when a view appears. This is useful for tasks like loading data or performing computations as the view comes into view.
If you are interested in optimizing performance and understanding how SwiftUI handles view updates, you might find the session Optimize SwiftUI performance with Instruments (04:20) helpful. It discusses diagnosing and fixing long view body updates, which can be relevant when dealing with lazy stacks and scroll views.

What’s new in SwiftUI
Learn what’s new in SwiftUI to build great apps for any Apple platform. We’ll explore how to give your app a brand new look and feel with Liquid Glass. Discover how to boost performance with framework enhancements and new instruments, and integrate advanced capabilities like web content and rich text editing. We’ll also show you how SwiftUI is expanding to more places, including laying out views in three dimensions.

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.

Profile and optimize power usage in your app
Learn how to optimize your app for maximum battery life. Discover how to identify the root cause of power issues in your app — whether you can reproduce the issue while connected to Xcode or on the go. Find out how to measure power use so you can make better decisions about new features and proactively build more efficient apps.