1. Define the refactor contract
“Clean up this view” leaves the model free to change naming, layout, storage and architecture together. Narrow the task: extract the summary card and action row from a large detail screen while keeping displayed values, button actions, navigation and accessibility labels unchanged.
Capture a baseline using representative data: normal content, a long title, an empty state and an active edit where relevant. Record one important interaction, such as entering a draft, opening a sheet, dismissing it and confirming that the draft remains. A screenshot alone does not capture that behavior.
2. Choose a boundary with explicit inputs
A useful extracted view has a clear purpose and explicit inputs. Decide whether it displays an immutable value, edits shared data through an appropriate connection, or owns temporary local state. Do not silently turn shared state into an independent copy merely to make a new initializer convenient.
SwiftUI identity and lifetime affect how state persists across updates. [1] After extraction, inspect the call site as well as the new component. A new conditional branch, a different identifier or a relocated state owner can change behavior even when the rendered text looks identical.
3. Review the changes that are easy to miss
| Boundary | Question before accepting |
|---|---|
| State | Did the owner or reset point change? |
| Identity | Will the same logical content retain the intended identity? |
| Modifiers | Did padding, gestures or environment modifiers move to a different level? |
| Actions | Does each callback still reach the same operation exactly as intended? |
| Navigation | Are selection, sheet presentation and dismissal still driven by the right values? |
| Accessibility | Do labels, grouping and focus remain meaningful? |
Modifier placement deserves a visual comparison, not an assumption. Moving padding outside a container, for example, changes which part receives that padding. Inspect the result with the same fixture and available width before calling it equivalent.
4. Separate extraction from redesign
Start with one component, build, compare the baseline and inspect the diff. Once that boundary is sound, continue to the next. Keep optional naming cleanup, new styling and dependency changes out of the first pass unless required for the extraction. Smaller coherent diffs make accidental behavior changes easier to spot.
When a better design would intentionally change behavior, describe it as a separate choice with new acceptance criteria. Do not disguise it as an implementation detail inside a behavior-preserving refactor.
Refactor [view] by extracting [specific component]. Preserve displayed content, layout, actions, navigation and labels. First map state ownership and identity at the call site. Do not combine this with a redesign, storage migration or new dependency. Extract one boundary, inspect the diff and verify [baseline scenarios]. Report where state now lives, modifier changes, actual checks and gaps.
5. Verify the interaction, not just compilation
Build the same target, compare the agreed visual states and replay the original interaction sequence. Run existing tests that exercise the extracted behavior and inspect their actual results. [2] Check particularly that edits, navigation and cancellation retain the intended values.
Finish by describing the new component boundary, where state remains owned, and which evidence supports equivalence. Record any unverified configurations. A model-generated assurance that the change is “purely structural” should be checked against the code and behavior it actually changed.
Common questions
Does extracting a view always reset state?
No. The risk depends on the resulting ownership, identity and lifetime. Inspect those boundaries and replay the relevant interaction instead of assuming all extraction is unsafe.
Is a smaller file the main success criterion?
No. A clearer responsibility boundary is useful when behavior remains correct and the code is easier to maintain. Line count alone does not establish either outcome.
Sources and next steps
Technical references below were checked on October 9, 2026. The diagnostic sequence, prompts and acceptance criteria are Relayard editorial guidance. Scenarios illustrate a method; they are not reported project test results. Available tools depend on the actual client and setup.