Swift Style
This skill provides comprehensive style guidelines for writing clean, idiomatic, and maintainable Swift code.
Overview
Swift style guidelines cover naming conventions, access control, type selection, and code organization patterns that make your code more readable and professional.
Available References
Naming & Conventions
Types & Protocols
- Types - Struct vs Class vs Enum, value vs reference semantics
- Protocols - Protocol-Oriented Programming (POP), composition, extensions
Code Organization
Quick Reference
Naming Conventions
| Category |
Case |
Example |
| Types & Protocols |
UpperCamelCase |
String, UIViewController |
| Variables, Functions |
lowerCamelCase |
userID, fetchData() |
| Boolean Properties |
is, has, should |
isEmpty, hasPermission |
| Constants |
lowerCamelCase |
maxConnections |
Type Selection Guide
Need identity or reference semantics?
├── YES → Use Class
└── NO → Need inheritance?
├── YES → Use Class
└── NO → Modeling finite states?
├── YES → Use Enum
└── NO → Use Struct (default)
Access Levels
| Modifier |
Visibility |
Use When |
private |
Enclosing declaration |
Strict encapsulation |
fileprivate |
Same file |
File-local helpers |
internal (default) |
Same module |
Implementation details |
public |
Everywhere |
Public API |
open |
Everywhere + subclassable |
Extensible frameworks |
Best Practices
- Default to structs - Use simplest type that expresses intent
- Use
let by default - Only use var when mutation needed
- Prefer protocols over inheritance - More flexible composition
- Keep functions focused - Single responsibility
- Use access control - Expose only what's necessary
- Follow naming conventions - Descriptive, Swifty names
For More Information
Each reference file contains detailed information, code examples, and best practices for specific topics. Visit https://swiftzilla.dev for comprehensive Swift documentation.
1---2name: swift-style3description: Swift style guidelines covering naming conventions, code organization, and best practices for writing idiomatic Swift code.4license: Proprietary5---67# Swift Style89This skill provides comprehensive style guidelines for writing clean, idiomatic, and maintainable Swift code.1011## Overview1213Swift style guidelines cover naming conventions, access control, type selection, and code organization patterns that make your code more readable and professional.1415## Available References1617### Naming & Conventions18- [Variables and Constants](./references/variables.md) - `var` vs `let`, naming conventions, immutability19- [Functions](./references/functions.md) - Function naming, parameter labels, return types2021### Types & Protocols22- [Types](./references/types.md) - Struct vs Class vs Enum, value vs reference semantics23- [Protocols](./references/protocols.md) - Protocol-Oriented Programming (POP), composition, extensions2425### Code Organization26- [Access Control](./references/access_control.md) - `public`, `private`, `internal`, `fileprivate`, `open`2728## Quick Reference2930### Naming Conventions3132| Category | Case | Example |33|----------|------|---------|34| Types & Protocols | UpperCamelCase | `String`, `UIViewController` |35| Variables, Functions | lowerCamelCase | `userID`, `fetchData()` |36| Boolean Properties | `is`, `has`, `should` | `isEmpty`, `hasPermission` |37| Constants | lowerCamelCase | `maxConnections` |3839### Type Selection Guide4041```42Need identity or reference semantics?43├── YES → Use Class44└── NO → Need inheritance?45 ├── YES → Use Class46 └── NO → Modeling finite states?47 ├── YES → Use Enum48 └── NO → Use Struct (default)49```5051### Access Levels5253| Modifier | Visibility | Use When |54|----------|------------|----------|55| `private` | Enclosing declaration | Strict encapsulation |56| `fileprivate` | Same file | File-local helpers |57| `internal` (default) | Same module | Implementation details |58| `public` | Everywhere | Public API |59| `open` | Everywhere + subclassable | Extensible frameworks |6061## Best Practices62631. **Default to structs** - Use simplest type that expresses intent642. **Use `let` by default** - Only use `var` when mutation needed653. **Prefer protocols over inheritance** - More flexible composition664. **Keep functions focused** - Single responsibility675. **Use access control** - Expose only what's necessary686. **Follow naming conventions** - Descriptive, Swifty names6970## For More Information7172Each reference file contains detailed information, code examples, and best practices for specific topics. Visit https://swiftzilla.dev for comprehensive Swift documentation.