swift-patterns-skill
AGENTS.md9 starsChanged 9 months agoMITView on GitHub
This document provides guidance for AI agents working with this skill to ensure consistency and avoid common pitfalls. Exception: Mention organization patterns as optional suggestions for readability, never as requirements. Exception: Suggest separating business logic for testability without enforcing how. Exception: Mention that users can profile with Instruments if performance issues arise, but don't provide detailed instructions. Use "suggest" or "consider" for optional optimizations: - ✅ "Consider downsampling images when using UIImage(data:)" - ❌ "Always downsample images" Use "always" or…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,337 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- swift-patternsSkill
The file
We split this AGENTS.md into the rules it gives an agent
11 rules. About 0 are common, 11 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
This is a Swift and SwiftUI skill: Do not include:
- Distinctive: line 14
Do not include formatting/linting rules: Avoid:
- Distinctive: line 24
Stick to facts, not architectures: Avoid:
- Distinctive: line 34
Agents cannot use external tools: Do not include:
- Distinctive: line 77
Don't mandate it as "always required"
- Distinctive: line 144
When adding new content:
- Distinctive: line 145
Ask: "Is this Swift-specific?"
- Distinctive: line 146
Ask: "Is this a fact or an opinion?"
- Distinctive: line 147
Ask: "Can agents actually use this?"
- Distinctive: line 148
Ask: "Is this about correctness or style?"
- Distinctive: line 150
If unsure, err on the side of excluding content.
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Agent Guidelines for Swift Patterns
This document provides guidance for AI agents working with this skill to ensure consistency and avoid common pitfalls.
Core Principles
1. Swift and SwiftUI Focus
This is a Swift and SwiftUI skill. Do not include:
- Server-side Swift patterns
- UIKit patterns (except when bridging is necessary)
- Deep Swift concurrency patterns (actors, Sendable, etc.) — use
.taskfor SwiftUI async work when needed
2. No Code Formatting or Linting
Do not include formatting/linting rules. Avoid:
- Property ordering requirements (environment, state, body, etc.)
- Code organization mandates
- Whitespace or indentation rules
- Naming convention enforcement
- File structure requirements
Exception: Mention organization patterns as optional suggestions for readability, never as requirements.
3. No Architectural Opinions
Stick to facts, not architectures. Avoid:
- Enforcing MVVM, MVC, VIPER, or any specific architecture
- Mandating view model patterns
- Requiring specific folder structures
- Dictating dependency injection patterns
- Prescribing router/coordinator patterns
Exception: Suggest separating business logic for testability without enforcing how.
4. No Tool-Specific Instructions
Agents cannot use external tools. Do not include:
- Xcode Instruments profiling instructions
- Debugging tool usage
- IDE-specific features
- Command-line tool usage beyond basic git
Exception: Mention that users can profile with Instruments if performance issues arise, but don't provide detailed instructions.
Content Guidelines
Suggestions vs Requirements
Use "suggest" or "consider" for optional optimizations:
- ✅ "Consider downsampling images when using
UIImage(data:)" - ❌ "Always downsample images"
Use "always" or "never" only for correctness issues:
- ✅ "Never use
.indicesfor dynamic ForEach content" - ✅ "Always mark
@Stateasprivate"
Performance Optimizations
Present performance optimizations as optional improvements:
- Image downsampling: Suggest when
UIImage(data:)is encountered - POD view wrappers: Mention as advanced optimization technique
- Equatable conformance: Suggest for expensive views
Do not automatically apply optimizations. Let developers decide based on their performance needs.
Modern API Usage
Enforce modern API usage for correctness:
- ✅
foregroundStyle()instead offoregroundColor() - ✅
NavigationStackinstead ofNavigationView - ✅
@Observableinstead ofObservableObjectfor new code
These are about using current, non-deprecated APIs, not optimization.
State Management
Be clear about @MainActor requirements:
- Mention that
@Observableclasses may need@MainActor - Note that projects with default actor isolation don't need explicit
@MainActor - Don't mandate it as "always required"
What to Include
✅ Include These Topics:
- Property wrapper selection (
@State,@Binding,@Observable, etc.) - Modern API replacements for deprecated APIs
- View composition and extraction patterns
- Performance patterns (stable identity, lazy loading, etc.)
- Common pitfalls and how to avoid them
- Sheet, navigation, and list patterns
- Liquid Glass API usage (iOS 26+)
- Accessibility best practices
❌ Exclude These Topics:
- Swift concurrency deep dives (actors, sendable, etc.)
- Code formatting and style rules
- Architectural patterns and mandates
- Tool usage instructions (Instruments, debuggers)
- File organization requirements
- Testing framework setup (XCTest configuration, CI pipelines)
- Build system configuration
- Project structure mandates
Language and Tone
Use Clear, Direct Language:
- "Use X instead of Y" (for deprecated APIs)
- "Consider X when Y" (for optimizations)
- "Avoid X because Y" (for anti-patterns)
- "X is preferred over Y" (for best practices)
Avoid Prescriptive Language:
- ❌ "You must organize properties in this order"
- ❌ "Always use MVVM architecture"
- ❌ "Profile with Instruments following these steps"
- ❌ "Structure your project like this"
Examples
Good Example:
## ForEach Identity
**Always provide stable identity for `ForEach`.** Never use `.indices` for dynamic content.
When you encounter `UIImage(data:)`, consider suggesting image downsampling as a performance optimization.Bad Example:
## View Organization
**Always organize view properties in this order:**
1. Environment
2. State
3. Body
4. Helpers
**Use Instruments to profile:**
1. Open Instruments
2. Select Swift template
3. Record and analyze...Updating the Skill
When adding new content:
- Ask: "Is this Swift-specific?"
- Ask: "Is this a fact or an opinion?"
- Ask: "Can agents actually use this?"
- Ask: "Is this about correctness or style?"
If unsure, err on the side of excluding content. It's better to have a focused, factual skill than a comprehensive but opinionated one.
Summary
Focus: Swift APIs, patterns, and correctness Avoid: Formatting, architecture, tools, Swift language features Tone: Factual, helpful, non-prescriptive Goal: Make agents Swift experts without enforcing opinions
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

