swift-style
Skill0 starsChanged 3 months agoMITView on GitHub
Swift code style conventions for clean, readable code. Use when writing Swift code to ensure consistent formatting, naming, organization, and idiomatic patterns.
In this repository21 other files it gives its agents.
- animateSkill
- composable-architectureSkill
- find-animation-opportunitiesSkill
- generating-swift-package-docsSkill
- hapticsSkill
- improve-animationsSkill
- ios-26-platformSkill
- ios-higSkill
- ios-simulator-skillSkill
- localizationSkill
- review-animationsSkill
- spm-build-analysisSkill
- storekitSkill
- swift-concurrencySkill
- swift-dataSkill
- swift-diagnosticsSkill
- swift-networkingSkill
- swift-testingSkill
- swiftuiSkill
- write-swiftSkill
- xcode-buildSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 4 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 21
No abbreviations except universal (URL, ID)
- Distinctive: line 48
Use extensions and MARK comments:
- Very specific: line 67
Avoid self unless required by compiler.
- Very specific: line 110
Don't add internal (it's the default)
- Very specific: line 125
Use // or ///, avoid /* */
- Distinctive: line 126
Keep up-to-date or delete
- Distinctive: line 130
Use case-less enum for namespacing:
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill 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
Swift Style Guide
Code style conventions for clean, readable Swift code.
Core Principles
Clarity > Brevity > Consistency
Code should compile without warnings.
Naming
UpperCamelCase— Types, protocolslowerCamelCase— Everything else- Clarity at call site
- No abbreviations except universal (URL, ID)
// Preferred
let maximumWidgetCount = 100
func fetchUser(byID id: String) -> UserGolden Path
Left-hand margin is the happy path. Don't nest if statements.
// Preferred
func process(value: Int?) throws -> Result {
guard let value = value else {
throw ProcessError.nilValue
}
guard value > 0 else {
throw ProcessError.invalidValue
}
return compute(value)
}Code Organization
Use extensions and MARK comments:
class MyViewController: UIViewController {
// Core implementation
}
// MARK: - UITableViewDataSource
extension MyViewController: UITableViewDataSource { }Spacing
- Braces open on same line, close on new line
- One blank line between methods
- Colon: no space before, one space after
Self
Avoid self unless required by compiler.
// Preferred
func configure() {
backgroundColor = .systemBackground
}Computed Properties
Omit get for read-only:
var diameter: Double {
radius * 2
}Closures
Trailing closure only for single closure parameter.
Type Inference
Let compiler infer when clear. For empty collections, use type annotation:
var names: [String] = []Syntactic Sugar
// Preferred
var items: [String]
var cache: [String: Int]
var name: String?Access Control
privateoverfileprivate- Don't add
internal(it's the default) - Access control as leading specifier
Memory Management
resource.request().onComplete { [weak self] response in
guard let self else { return }
self.updateModel(response)
}Comments
- Explain why, not what
- Use
//or///, avoid/* */ - Keep up-to-date or delete
Constants
Use case-less enum for namespacing:
enum Math {
static let pi = 3.14159
}Common Mistakes
- Abbreviations beyond URL, ID, UUID — Abbreviations like
cfg,mgr,ctx,deschurt readability. Spell them out:configuration,manager,context,description. The three exceptions are URL, ID, UUID. - Nested guard/if statements — Deep nesting makes code hard to follow. Use early returns and guards to keep the happy path left-aligned.
- Inconsistent self usage — Either always omit
self(preferred) or always use it. Mixing makes code scanning harder and confuses capture semantics. - Overly generic type names —
Manager,Handler,Helper,Coordinatorare too vague. Names should explain responsibility:PaymentProcessor,EventDispatcher,ImageCache,NavigationCoordinator. - Implied access control — Don't skip access control. Explicit
private,publichelps future maintainers understand module boundaries.internalis default, so omit it.
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.

