The task modifier starts asynchronous work associated with a view's lifetime. SwiftUI can cancel that task when the view disappears or when a task(id:) identifier changes. This is usually a better lifecycle match than starting untracked work from body or init.
Asynchronous UI needs an explicit state model. Loading, content, empty, and failure are different user experiences, not only an optional array and a Boolean. An enum prevents contradictory states and gives each branch the information it requires.
Cancellation is expected control flow. Let cancellation propagate, check it during long work, and avoid replacing useful content with a cancellation error. For input-driven work such as search, task(id:) cancels the prior task as the ID changes; a small delay can provide cooperative debouncing.