Coding Best Practices Skill
Reviews Swift/iOS code for adherence to modern Swift idioms, Apple platform best practices, architecture patterns, and code quality standards.
When This Skill Activates
Use this skill when the user:
- Asks for code review or code quality check
- Mentions "best practices", "clean code", or "refactoring"
- Wants to improve existing code
- Requests architecture or design pattern review
- Asks about Swift idioms or modern patterns
- Wants performance optimization suggestions
Review Process
1. Identify Scope
- If user specifies files/classes, review those
- Otherwise, ask which areas to focus on or review recent changes
- Prioritize ViewModels, business logic, and data layer over simple views
2. Load Reference Patterns
Before starting the review, familiarize yourself with the reference patterns by reading the following files in .claude/skills/coding-best-practices/:
- swift-patterns.md - Optionals, type safety, collections, error handling, naming
- swiftui-patterns.md - State management, view composition, performance
- architecture-patterns.md - MVVM, code organization, memory management, security
- coredata-patterns.md - Core Data best practices, fetching, saving, relationships
3. Review Categories
Apply these review categories based on the code type:
For All Code:
- Swift language idioms (optionals, type safety, collections)
- Naming conventions
- Error handling
- Memory management
For SwiftUI Code:
- State management (
@State, @Observable + @Bindable; legacy @StateObject / @ObservedObject pre-iOS 17)
- View composition and performance
- MVVM separation
For ViewModels:
- Business logic placement
- MVVM architecture adherence
- Testability (dependency injection)
For Core Data Code:
- Context management
- Save/fetch patterns
- Relationship handling
- CloudKit integration
4. Review Output Format
Provide review in this structure:
✅ Strengths Found
- List well-implemented patterns
- Highlight good practices
- Acknowledge clean code sections
⚠️ Issues Found
For each issue, use this format:
Category: [Category Name]
[Priority]: [File.swift:line] - [Issue description]
// Current:
[problematic code]
// Suggested:
[improved code]
// Reason: [explanation]
Priority Levels:
- High: Will cause bugs, crashes, or serious issues
- Medium: Inefficient, hard to maintain, or non-idiomatic
- Low: Minor improvements, nice-to-haves
📊 Code Quality Score
Overall: X/10
- Swift Idioms: X/10
- Architecture: X/10
- Error Handling: X/10
- Naming: X/10
- Organization: X/10
- Performance: X/10
📋 Recommendations
- High Priority: [Critical issues]
- Medium Priority: [Improvements]
- Low Priority: [Nice-to-haves]
🔧 Quick Wins
List 3-5 easy fixes that provide immediate value
Review Checklist
Use this comprehensive checklist during review:
Swift Language
SwiftUI
Architecture
Core Data
Memory Management
Testing & Security
Example Review Output
Reviewing: ExpenseViewModel.swift
✅ Strengths Found
- Excellent use of @Published properties
- Clean separation between public and private methods
- Good error handling with custom error types
- Proper use of guard statements for early returns
⚠️ Issues Found
**Category: Optionals Handling**
**High Priority: ExpenseViewModel.swift:45** - Force unwrapping
// Current:
let payer = expense.payer!
// Suggested:
guard let payer = expense.payer else {
print("Expense has no payer")
return
}
// Reason: Force unwrapping will crash if payer is nil. Use guard for safe unwrapping.
**Category: Core Data**
**Medium Priority: ExpenseViewModel.swift:89** - Saving without checking hasChanges
// Current:
try? context.save()
// Suggested:
if context.hasChanges {
do {
try context.save()
} catch {
print("Failed to save: \(error.localizedDescription)")
}
}
// Reason: Check hasChanges to avoid unnecessary saves. Handle errors properly.
**Category: Collections**
**Low Priority: ExpenseViewModel.swift:123** - Inefficient filtering
// Current:
let found = expenses.filter { $0.id == targetId }.first
// Suggested:
let found = expenses.first { $0.id == targetId }
// Reason: first(where:) stops at first match, filter processes entire array.
📊 Code Quality Score
**Overall: 7/10**
- Swift Idioms: 6/10 (force unwrapping, inefficient collection usage)
- Architecture: 9/10 (excellent MVVM separation)
- Error Handling: 7/10 (using try? too often)
- Naming: 9/10 (clear, descriptive names)
- Organization: 8/10 (good marks, could improve grouping)
- Performance: 7/10 (some inefficient patterns)
📋 Recommendations
1. **High Priority**: Remove all force unwrapping (5 instances found)
2. **Medium Priority**: Improve error handling (don't swallow errors with try?)
3. **Low Priority**: Use first(where:) instead of filter().first
🔧 Quick Wins
1. Replace `expense.payer!` with safe unwrapping (ExpenseViewModel.swift:45)
2. Add hasChanges check before context.save() (ExpenseViewModel.swift:89)
3. Use first(where:) for finding items (ExpenseViewModel.swift:123)
Tips for Effective Reviews
Be Constructive
- Provide clear code examples for every issue
- Explain WHY, not just WHAT
- Be educational, not judgmental
Consider Context
- Some patterns are valid in certain scenarios
- Balance idealism with pragmatism
- Consider project constraints
Prioritize Impact
- Focus on issues that affect correctness first
- Then performance and maintainability
- Style issues last
Actionable Feedback
- Provide specific line numbers
- Show exact code to change
- Explain expected behavior
References
Notes
- Read the reference pattern files for detailed examples
- Focus on the most impactful improvements first
- Provide code examples for all suggested changes
- Reference exact file locations (filename.swift:lineNumber)
- Be thorough but constructive
Source: flight505/skill-forge — distributed by TomeVault.
1---2name: coding-best-practices3description: Reviews Swift/iOS code for adherence to modern Swift idioms, Apple platform best practices, architecture patterns, and code quality standards. Use when user mentions best practices, code review, clean code, refactoring, or wants to improve code quality. Use when this capability is needed.4---56# Coding Best Practices Skill78Reviews Swift/iOS code for adherence to modern Swift idioms, Apple platform best practices, architecture patterns, and code quality standards.910## When This Skill Activates1112Use this skill when the user:1314- Asks for code review or code quality check15- Mentions "best practices", "clean code", or "refactoring"16- Wants to improve existing code17- Requests architecture or design pattern review18- Asks about Swift idioms or modern patterns19- Wants performance optimization suggestions2021## Review Process2223### 1. Identify Scope2425- If user specifies files/classes, review those26- Otherwise, ask which areas to focus on or review recent changes27- Prioritize ViewModels, business logic, and data layer over simple views2829### 2. Load Reference Patterns3031Before starting the review, familiarize yourself with the reference patterns by reading the following files in `.claude/skills/coding-best-practices/`:3233- **swift-patterns.md** - Optionals, type safety, collections, error handling, naming34- **swiftui-patterns.md** - State management, view composition, performance35- **architecture-patterns.md** - MVVM, code organization, memory management, security36- **coredata-patterns.md** - Core Data best practices, fetching, saving, relationships3738### 3. Review Categories3940Apply these review categories based on the code type:4142**For All Code:**4344- Swift language idioms (optionals, type safety, collections)45- Naming conventions46- Error handling47- Memory management4849**For SwiftUI Code:**5051- State management (`@State`, `@Observable` + `@Bindable`; legacy `@StateObject` / `@ObservedObject` pre-iOS 17)52- View composition and performance53- MVVM separation5455**For ViewModels:**5657- Business logic placement58- MVVM architecture adherence59- Testability (dependency injection)6061**For Core Data Code:**6263- Context management64- Save/fetch patterns65- Relationship handling66- CloudKit integration6768### 4. Review Output Format6970Provide review in this structure:7172#### ✅ Strengths Found7374- List well-implemented patterns75- Highlight good practices76- Acknowledge clean code sections7778#### ⚠️ Issues Found7980For each issue, use this format:8182**Category: [Category Name]**8384**[Priority]: [File.swift:line]** - [Issue description]8586```swift87// Current:88[problematic code]8990// Suggested:91[improved code]9293// Reason: [explanation]94```9596**Priority Levels:**9798- **High**: Will cause bugs, crashes, or serious issues99- **Medium**: Inefficient, hard to maintain, or non-idiomatic100- **Low**: Minor improvements, nice-to-haves101102#### 📊 Code Quality Score103104**Overall: X/10**105106- Swift Idioms: X/10107- Architecture: X/10108- Error Handling: X/10109- Naming: X/10110- Organization: X/10111- Performance: X/10112113#### 📋 Recommendations1141151. **High Priority**: [Critical issues]1162. **Medium Priority**: [Improvements]1173. **Low Priority**: [Nice-to-haves]118119#### 🔧 Quick Wins120121List 3-5 easy fixes that provide immediate value122123## Review Checklist124125Use this comprehensive checklist during review:126127### Swift Language128129- [ ] No force unwrapping unless intentional130- [ ] Proper optional handling (guard, if let, ??)131- [ ] Enums instead of string/int constants132- [ ] Functional collection operations (map, filter, etc.)133- [ ] Proper error handling (not silent try?)134- [ ] Clear, descriptive naming135136### SwiftUI137138- [ ] Correct property wrapper usage139- [ ] No ViewModels created in body140- [ ] Views broken into components141- [ ] No heavy computation in body142- [ ] Single source of truth143144### Architecture145146- [ ] MVVM separation maintained147- [ ] Business logic in ViewModels148- [ ] UI logic in Views only149- [ ] Proper code organization with MARK150- [ ] Private by default151152### Core Data153154- [ ] Using shared context155- [ ] hasChanges check before save156- [ ] Typed fetch requests157- [ ] Safe property access158- [ ] Proper error handling159160### Memory Management161162- [ ] [weak self] in escaping closures163- [ ] Weak delegates164- [ ] No retain cycles165166### Testing & Security167168- [ ] Testable code structure169- [ ] Dependency injection170- [ ] No hardcoded secrets171- [ ] Input validation172- [ ] Safe logging173174## Example Review Output175176```177Reviewing: ExpenseViewModel.swift178179✅ Strengths Found180- Excellent use of @Published properties181- Clean separation between public and private methods182- Good error handling with custom error types183- Proper use of guard statements for early returns184185⚠️ Issues Found186187**Category: Optionals Handling**188189**High Priority: ExpenseViewModel.swift:45** - Force unwrapping190// Current:191let payer = expense.payer!192193// Suggested:194guard let payer = expense.payer else {195 print("Expense has no payer")196 return197}198199// Reason: Force unwrapping will crash if payer is nil. Use guard for safe unwrapping.200201**Category: Core Data**202203**Medium Priority: ExpenseViewModel.swift:89** - Saving without checking hasChanges204// Current:205try? context.save()206207// Suggested:208if context.hasChanges {209 do {210 try context.save()211 } catch {212 print("Failed to save: \(error.localizedDescription)")213 }214}215216// Reason: Check hasChanges to avoid unnecessary saves. Handle errors properly.217218**Category: Collections**219220**Low Priority: ExpenseViewModel.swift:123** - Inefficient filtering221// Current:222let found = expenses.filter { $0.id == targetId }.first223224// Suggested:225let found = expenses.first { $0.id == targetId }226227// Reason: first(where:) stops at first match, filter processes entire array.228229📊 Code Quality Score230**Overall: 7/10**231232- Swift Idioms: 6/10 (force unwrapping, inefficient collection usage)233- Architecture: 9/10 (excellent MVVM separation)234- Error Handling: 7/10 (using try? too often)235- Naming: 9/10 (clear, descriptive names)236- Organization: 8/10 (good marks, could improve grouping)237- Performance: 7/10 (some inefficient patterns)238239📋 Recommendations2401. **High Priority**: Remove all force unwrapping (5 instances found)2412. **Medium Priority**: Improve error handling (don't swallow errors with try?)2423. **Low Priority**: Use first(where:) instead of filter().first243244🔧 Quick Wins2451. Replace `expense.payer!` with safe unwrapping (ExpenseViewModel.swift:45)2462. Add hasChanges check before context.save() (ExpenseViewModel.swift:89)2473. Use first(where:) for finding items (ExpenseViewModel.swift:123)248```249250## Tips for Effective Reviews251252### Be Constructive253254- Provide clear code examples for every issue255- Explain WHY, not just WHAT256- Be educational, not judgmental257258### Consider Context259260- Some patterns are valid in certain scenarios261- Balance idealism with pragmatism262- Consider project constraints263264### Prioritize Impact265266- Focus on issues that affect correctness first267- Then performance and maintainability268- Style issues last269270### Actionable Feedback271272- Provide specific line numbers273- Show exact code to change274- Explain expected behavior275276## References277278- [Swift API Design Guidelines](https://swift.org/documentation/api-design-guidelines/)279- [Swift.org Documentation](https://docs.swift.org/)280- [SwiftUI Best Practices](https://developer.apple.com/documentation/swiftui)281- [Core Data Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreData/)282283## Notes284285- Read the reference pattern files for detailed examples286- Focus on the most impactful improvements first287- Provide code examples for all suggested changes288- Reference exact file locations (filename.swift:lineNumber)289- Be thorough but constructive290291---292> Source: [flight505/skill-forge](https://github.com/flight505/skill-forge) — distributed by [TomeVault](https://tomevault.io).293<!-- tomevault:4.0:skill_md:2026-05-23 -->