Swift — iOS/macOS Development
Guidelines for writing, reviewing, and rating Swift code.
Code Style
Naming
- Types:
UpperCamelCase — struct MessageView, class NetworkManager
- Functions/properties:
lowerCamelCase — func fetchMessages(), var isLoading
- Constants:
lowerCamelCase — let maxRetries = 3
- Protocols: Describe capability —
Codable, Sendable, MessageHandling
Structure
- One type per file (matching filename)
- Use extensions to organize protocol conformances
- Prefer
struct over class unless reference semantics are needed
- Prefer
let over var unless mutation is required
Modern Swift Patterns
- Use
async/await over completion handlers
- Use
Actor for thread-safe mutable state
- Use
@Observable (iOS 17+) or ObservableObject for state management
- Use structured concurrency (
TaskGroup, async let) over DispatchQueue
- Use
Codable for serialization
- Use
Result type for error handling in non-async contexts
SwiftUI Conventions
struct ContentView: View {
@State private var items: [Item] = []
var body: some View {
List(items) { item in
ItemRow(item: item)
}
.task {
items = await fetchItems()
}
}
}
- Extract subviews when
body exceeds ~30 lines
- Use
@State for local view state, @Binding for parent-owned state
- Use
.task {} for async work on view appear
- Prefer
NavigationStack over deprecated NavigationView
Code Review Checklist
When reviewing or rating Swift code, check:
- Safety: No force unwraps (
!) unless guaranteed — prefer guard let / if let
- Memory: No retain cycles — use
[weak self] in closures that capture self
- Concurrency: Proper
@Sendable conformance, no data races
- Error handling:
do/catch with specific error types, not bare try?
- API design: Clear parameter labels, consistent naming
- Performance: Avoid unnecessary allocations in hot paths
- Accessibility: VoiceOver labels, Dynamic Type support
- Testing: Protocols for dependency injection, testable architecture
Rating Scale
When asked to rate Swift code:
| Rating |
Meaning |
| A |
Production-ready, follows all conventions, well-tested |
| B |
Good with minor issues — missing docs, small style inconsistencies |
| C |
Functional but has code smells — force unwraps, retain cycles, unclear naming |
| D |
Significant issues — race conditions, memory leaks, no error handling |
| F |
Broken or dangerous — crashes, security vulnerabilities, undefined behavior |
Source: CorvidLabs/corvid-agent — distributed by TomeVault.
1---2name: corvidlabs-corvid-agent-swift3description: Swift — iOS/macOS Development4---56# Swift — iOS/macOS Development78Guidelines for writing, reviewing, and rating Swift code.910## Code Style1112### Naming1314- **Types**: `UpperCamelCase` — `struct MessageView`, `class NetworkManager`15- **Functions/properties**: `lowerCamelCase` — `func fetchMessages()`, `var isLoading`16- **Constants**: `lowerCamelCase` — `let maxRetries = 3`17- **Protocols**: Describe capability — `Codable`, `Sendable`, `MessageHandling`1819### Structure2021- One type per file (matching filename)22- Use extensions to organize protocol conformances23- Prefer `struct` over `class` unless reference semantics are needed24- Prefer `let` over `var` unless mutation is required2526### Modern Swift Patterns2728- Use `async/await` over completion handlers29- Use `Actor` for thread-safe mutable state30- Use `@Observable` (iOS 17+) or `ObservableObject` for state management31- Use structured concurrency (`TaskGroup`, `async let`) over `DispatchQueue`32- Use `Codable` for serialization33- Use `Result` type for error handling in non-async contexts3435## SwiftUI Conventions3637```swift38struct ContentView: View {39 @State private var items: [Item] = []4041 var body: some View {42 List(items) { item in43 ItemRow(item: item)44 }45 .task {46 items = await fetchItems()47 }48 }49}50```5152- Extract subviews when `body` exceeds ~30 lines53- Use `@State` for local view state, `@Binding` for parent-owned state54- Use `.task {}` for async work on view appear55- Prefer `NavigationStack` over deprecated `NavigationView`5657## Code Review Checklist5859When reviewing or rating Swift code, check:60611. **Safety**: No force unwraps (`!`) unless guaranteed — prefer `guard let` / `if let`622. **Memory**: No retain cycles — use `[weak self]` in closures that capture `self`633. **Concurrency**: Proper `@Sendable` conformance, no data races644. **Error handling**: `do/catch` with specific error types, not bare `try?`655. **API design**: Clear parameter labels, consistent naming666. **Performance**: Avoid unnecessary allocations in hot paths677. **Accessibility**: VoiceOver labels, Dynamic Type support688. **Testing**: Protocols for dependency injection, testable architecture6970## Rating Scale7172When asked to rate Swift code:7374| Rating | Meaning |75|--------|---------|76| A | Production-ready, follows all conventions, well-tested |77| B | Good with minor issues — missing docs, small style inconsistencies |78| C | Functional but has code smells — force unwraps, retain cycles, unclear naming |79| D | Significant issues — race conditions, memory leaks, no error handling |80| F | Broken or dangerous — crashes, security vulnerabilities, undefined behavior |8182---83> Source: [CorvidLabs/corvid-agent](https://github.com/CorvidLabs/corvid-agent) — distributed by [TomeVault](https://tomevault.io).84<!-- tomevault:4.0:skill_md:2026-06-16 -->