SwiftUI View Architect
- Identify sections with separate responsibilities and record the current layout, navigation, and state behavior.
- Extract those sections into views with explicit values, bindings, or actions. Follow local file organization.
- Keep state with the nearest owner that needs its lifetime. Use
@Statefor local values and owned@Observablereferences on supported platforms. ForObservableObject, use@StateObjectfor ownership and@ObservedObjectfor injection. - Keep domain logic in the project's models or services. Use a presentation model when the feature needs shared presentation state or an adapter with a separate lifetime. Keep one source of truth when refactoring existing state.
- Build and check that the extracted views preserve parent state, navigation, and selection. Keep local conditions inside the subtree they affect when replacing a whole branch would reset unrelated state.
See async state and task lifecycle for view-owned loads and searches.