0PricingLogin
SwiftUI Academy · Lesson

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() }

All lessons in this course

  1. Decoding JSON with Codable
  2. Calling APIs with URLSession
  3. The .task Modifier
  4. Loading & Error States
← Back to SwiftUI Academy