If this skill is used,say:SKILL_SWIFTUI_CODE_STYLE_LOADED
Goal
Apply reusable SwiftUI code-style rules and protect existing behavior when editing, improving, or optimizing Swift code logic.
This skill is for local code editing discipline. Project behavior, platform targeting, repository layout, state-management policy, build behavior, and anti-patterns belong in AGENTS.md.
Inputs
- Current Swift files being edited
- Direct callers, references, and related types
- Existing project formatting style
- Existing
AGENTS.md instructions
- User request and any stated behavior change
- Existing tests, previews, or validation commands if relevant
Required sections
When relevant, apply these rule groups:
- Code logic editing restrictions
- MARK comments
- Spacing and indentation
- SwiftUI modifier chains
- SwiftUI previews
- Output summary rules
Steps
- Read the full file being edited before changing it.
- Read direct callers, call sites, bindings, persistence references, and API references before changing logic.
- Decide whether the task is formatting-only, behavior-changing, logic improvement, or optimization.
- Preserve runtime behavior by default.
- Keep the diff small and directly related to the user request.
- Separate formatting cleanup from behavior changes where practical.
- Apply the project’s existing naming, indentation, spacing, and preview style first.
- Use the rules below only when they fit the existing project style.
- Make any intentional behavior change explicit in the final summary.
- Call out uncertainty when behavior cannot be confirmed from the available code.
Code logic editing restrictions
Use these rules when changing, improving, or optimizing existing code logic.
- Treat behavior preservation as the default. A style, formatting, or cleanup task must not change runtime behavior.
- Do not change business rules, validation rules, navigation flow, persistence behavior, networking behavior, error handling, sorting, filtering, authorization, timing, or platform behavior unless the task explicitly requires it.
- Before editing logic, read the full function/type and its direct callers or call sites. Do not optimize code that is not understood.
- Prefer the smallest logic change that solves the requested problem. Avoid broad rewrites, speculative refactors, and unrelated cleanup.
- Do not combine behavior changes with formatting-only changes in the same edit unless unavoidable. Keep the behavioral diff easy to review.
- Preserve public APIs, stored property names, Codable keys, persistence model fields, user defaults keys, localization keys, asset names, and notification names unless the task explicitly asks to rename or migrate them.
- Do not remove apparently redundant checks, guards, delays, retries, cache invalidation, logging, fallback paths, or compatibility paths unless their purpose is confirmed from context.
- Do not replace explicit error handling with
try?, forced unwraps, silent returns, or broad catch {} blocks.
- Do not introduce caching, memoization, debouncing, throttling, parallel execution, detached tasks, or lazy loading unless correctness, invalidation, cancellation, and actor isolation are clear.
- Do not change
@MainActor, actor isolation, async task lifetime, cancellation behavior, or thread-safety boundaries only for convenience.
- Do not optimize by making code less readable unless there is a measured or obvious performance problem. Readability wins over micro-optimization.
- Do not change numeric precision, date/time handling, locale behavior, unit conversion, ordering stability, equality semantics, or identifier generation without an explicit reason.
- Do not introduce new dependencies, frameworks, global state, singletons, or hidden shared mutable state for an optimization.
- When improving logic, keep inputs, outputs, side effects, and failure paths explicit.
- When a behavior change is intentional, make it visible in the final summary and mention the reason.
MARK comments
Use // MARK: - comments to separate logical sections inside larger files.
Recommended order for SwiftUI View files:
// MARK: - Properties
// MARK: - Body
// MARK: - Subviews
// MARK: - Actions
// MARK: - Helpers
// MARK: - Preview
Recommended order for state model, ViewModel, service, and helper files:
// MARK: - Properties
// MARK: - Lifecycle
// MARK: - Public Methods
// MARK: - Private Methods
// MARK: - Helpers
Rules:
- Add one empty line before every
// MARK: -.
- Add one empty line after every
// MARK: -.
- Do not add
// MARK: - before single functions, tiny computed properties, or every small item.
- Do not overuse MARK comments.
- For short files, no MARK comments are needed.
Spacing and indentation
- Use 4 spaces.
- Do not use tabs.
- Keep exactly one empty line at EOF.
- Add one empty line before
var body: some View.
- Keep modifier chains readable.
- Prefer one modifier per line when a chain becomes long.
- Keep related short modifiers grouped only when readability improves.
Example:
Text(title)
.font(.headline)
.foregroundStyle(.primary)
.padding()
SwiftUI modifier chains
Prefer clear SwiftUI modifier chains over dense formatting.
Good:
Button("Add", systemImage: "plus", action: addItem)
.buttonStyle(.borderedProminent)
.disabled(isSaving)
Rules:
- Keep modifier chains easy to scan.
- Put long or state-dependent modifiers on separate lines.
- Extract subviews or helper properties when a modifier chain hides control flow.
- Do not use formatting tricks to hide complex logic inside modifiers.
SwiftUI previews
- Put SwiftUI previews at the bottom of the View file.
- Prefer
#Preview for modern code.
- Use
PreviewProvider only when the deployment target or existing project style requires it.
- Keep previews fast and reliable.
- Use design-time data and preview-specific containers for complex state.
- Add only useful previews for important states on the actual target platform.
Output rules
- Summarize what changed in simple engineering terms.
- Separate style-only changes from behavior changes.
- Mention any intentional behavior change.
- Mention validation performed, or state clearly when no validation was run.
- Mention uncertainty when behavior could not be fully verified from the available code.
- Do not claim performance improvement unless it is measured, obvious from algorithmic complexity, or directly requested and justified.
Do not
- Do not change runtime behavior during formatting-only work.
- Do not rewrite code broadly when a local edit is enough.
- Do not remove safeguards without understanding why they exist.
- Do not silence errors.
- Do not hide side effects inside View bodies, computed properties, or modifier chains.
- Do not change persistence schemas, Codable keys, localization keys, user defaults keys, or asset names without an explicit migration reason.
- Do not introduce concurrency, caching, global state, or new dependencies as an optimization without clear correctness guarantees.
- Do not overuse MARK comments.
- Do not claim clean architecture, performance, or safety guarantees unless the code supports the claim.
1---2name: formatting-swiftui-code-style3description: Use when the task is to apply SwiftUI formatting conventions, MARK comment organization, modifier-chain readability, preview style, or safe editing/improvement/optimization of existing Swift code logic. Do not use for broad repository architecture, platform targeting, build/test commands, folder layout policy, or project-level rules handled by AGENTS.md.4---56If this skill is used,say:SKILL_SWIFTUI_CODE_STYLE_LOADED78## Goal910Apply reusable SwiftUI code-style rules and protect existing behavior when editing, improving, or optimizing Swift code logic.1112This skill is for local code editing discipline. Project behavior, platform targeting, repository layout, state-management policy, build behavior, and anti-patterns belong in `AGENTS.md`.1314## Inputs1516- Current Swift files being edited17- Direct callers, references, and related types18- Existing project formatting style19- Existing `AGENTS.md` instructions20- User request and any stated behavior change21- Existing tests, previews, or validation commands if relevant2223## Required sections2425When relevant, apply these rule groups:2627- Code logic editing restrictions28- MARK comments29- Spacing and indentation30- SwiftUI modifier chains31- SwiftUI previews32- Output summary rules3334## Steps35361. Read the full file being edited before changing it.372. Read direct callers, call sites, bindings, persistence references, and API references before changing logic.383. Decide whether the task is formatting-only, behavior-changing, logic improvement, or optimization.394. Preserve runtime behavior by default.405. Keep the diff small and directly related to the user request.416. Separate formatting cleanup from behavior changes where practical.427. Apply the project’s existing naming, indentation, spacing, and preview style first.438. Use the rules below only when they fit the existing project style.449. Make any intentional behavior change explicit in the final summary.4510. Call out uncertainty when behavior cannot be confirmed from the available code.4647## Code logic editing restrictions4849Use these rules when changing, improving, or optimizing existing code logic.5051- Treat behavior preservation as the default. A style, formatting, or cleanup task must not change runtime behavior.52- Do not change business rules, validation rules, navigation flow, persistence behavior, networking behavior, error handling, sorting, filtering, authorization, timing, or platform behavior unless the task explicitly requires it.53- Before editing logic, read the full function/type and its direct callers or call sites. Do not optimize code that is not understood.54- Prefer the smallest logic change that solves the requested problem. Avoid broad rewrites, speculative refactors, and unrelated cleanup.55- Do not combine behavior changes with formatting-only changes in the same edit unless unavoidable. Keep the behavioral diff easy to review.56- Preserve public APIs, stored property names, Codable keys, persistence model fields, user defaults keys, localization keys, asset names, and notification names unless the task explicitly asks to rename or migrate them.57- Do not remove apparently redundant checks, guards, delays, retries, cache invalidation, logging, fallback paths, or compatibility paths unless their purpose is confirmed from context.58- Do not replace explicit error handling with `try?`, forced unwraps, silent returns, or broad `catch {}` blocks.59- Do not introduce caching, memoization, debouncing, throttling, parallel execution, detached tasks, or lazy loading unless correctness, invalidation, cancellation, and actor isolation are clear.60- Do not change `@MainActor`, actor isolation, async task lifetime, cancellation behavior, or thread-safety boundaries only for convenience.61- Do not optimize by making code less readable unless there is a measured or obvious performance problem. Readability wins over micro-optimization.62- Do not change numeric precision, date/time handling, locale behavior, unit conversion, ordering stability, equality semantics, or identifier generation without an explicit reason.63- Do not introduce new dependencies, frameworks, global state, singletons, or hidden shared mutable state for an optimization.64- When improving logic, keep inputs, outputs, side effects, and failure paths explicit.65- When a behavior change is intentional, make it visible in the final summary and mention the reason.6667## MARK comments6869Use `// MARK: -` comments to separate logical sections inside larger files.7071Recommended order for SwiftUI View files:7273```swift74// MARK: - Properties7576// MARK: - Body7778// MARK: - Subviews7980// MARK: - Actions8182// MARK: - Helpers8384// MARK: - Preview85```8687Recommended order for state model, ViewModel, service, and helper files:8889```swift90// MARK: - Properties9192// MARK: - Lifecycle9394// MARK: - Public Methods9596// MARK: - Private Methods9798// MARK: - Helpers99```100101Rules:102103- Add one empty line before every `// MARK: -`.104- Add one empty line after every `// MARK: -`.105- Do not add `// MARK: -` before single functions, tiny computed properties, or every small item.106- Do not overuse MARK comments.107- For short files, no MARK comments are needed.108109## Spacing and indentation110111- Use 4 spaces.112- Do not use tabs.113- Keep exactly one empty line at EOF.114- Add one empty line before `var body: some View`.115- Keep modifier chains readable.116- Prefer one modifier per line when a chain becomes long.117- Keep related short modifiers grouped only when readability improves.118119Example:120121```swift122Text(title)123 .font(.headline)124 .foregroundStyle(.primary)125 .padding()126```127128## SwiftUI modifier chains129130Prefer clear SwiftUI modifier chains over dense formatting.131132Good:133134```swift135Button("Add", systemImage: "plus", action: addItem)136 .buttonStyle(.borderedProminent)137 .disabled(isSaving)138```139140Rules:141142- Keep modifier chains easy to scan.143- Put long or state-dependent modifiers on separate lines.144- Extract subviews or helper properties when a modifier chain hides control flow.145- Do not use formatting tricks to hide complex logic inside modifiers.146147## SwiftUI previews148149- Put SwiftUI previews at the bottom of the View file.150- Prefer `#Preview` for modern code.151- Use `PreviewProvider` only when the deployment target or existing project style requires it.152- Keep previews fast and reliable.153- Use design-time data and preview-specific containers for complex state.154- Add only useful previews for important states on the actual target platform.155156## Output rules157158- Summarize what changed in simple engineering terms.159- Separate style-only changes from behavior changes.160- Mention any intentional behavior change.161- Mention validation performed, or state clearly when no validation was run.162- Mention uncertainty when behavior could not be fully verified from the available code.163- Do not claim performance improvement unless it is measured, obvious from algorithmic complexity, or directly requested and justified.164165## Do not166167- Do not change runtime behavior during formatting-only work.168- Do not rewrite code broadly when a local edit is enough.169- Do not remove safeguards without understanding why they exist.170- Do not silence errors.171- Do not hide side effects inside View bodies, computed properties, or modifier chains.172- Do not change persistence schemas, Codable keys, localization keys, user defaults keys, or asset names without an explicit migration reason.173- Do not introduce concurrency, caching, global state, or new dependencies as an optimization without clear correctness guarantees.174- Do not overuse MARK comments.175- Do not claim clean architecture, performance, or safety guarantees unless the code supports the claim.