Swift 6 · SwiftUI basics

Load data when a view appears

The task modifier runs async work and cancels it when the view goes away.

.task {
    items = (try? await loadItems()) ?? []
}

Official Swift 6 documentation

More swiftui basics commands

All swiftui basics commands · Swift 6 cheatsheet

Was this page helpful?