The .task Modifier
Load data when a view appears.
Loading When a View Appears
Often you want to fetch data the moment a screen shows. The .task modifier runs async work exactly when the view appears. ⏱️
Attaching .task
Add .task to any view and give it an async closure. SwiftUI starts that work as the view comes on screen.
List(users) { user in Text(user.name) }
.task { await load() }