| A view model / observable state object | use @Observable (macro) — NEVER ObservableObject + @Published |
A long loop or CPU-bound op inside a Task | call try Task.checkCancellation() (or check Task.isCancelled) inside the loop |
@MainActor on a whole class | move CPU-bound / non-UI methods OFF it (nonisolated) — NEVER blanket @MainActor to silence errors |
| A library API that throws | use typed throws: throws(MyError), not bare throws |
| A single-use resource (token, file handle, one-shot) | model it as struct Token: ~Copyable — NEVER a class with a copy() |
A type conforming to a protocol (Codable, Equatable, …) | put the conformance in extension MyType: Proto { } and remove : Proto from the declaration — NEVER inline on the declaration, and NEVER both inline and an extension (that double-declares conformance) |
| A SwiftUI view that needs a shared service / view model | receive it with @Environment(Type.self) — NEVER own it via @State private var vm = VM(), and NEVER wire it through an init(client:) / @StateObject |
A child view that edits state owned elsewhere (e.g. an EditProfileView) | take a @Binding to the real value (or commit through the owning model) — NEVER copy the value into a local @State and edit the copy |
| Any SwiftUI view | add a #Preview with mock data |