Covers all five SOLID principles with dedicated references (SRP, OCP, LSP, ISP, DIP), concurrency patterns (actors, @MainActor, Sendable), an anti-pattern catalog, and code templates for views, view models, services, protocols, and models.
Requires grepping the codebase for reusable protocols/services before writing new code, and checking shared locations (Core/Extensions/, Core/Utilities/, Core/Protocols/) before duplicating logic used by 2+ features.
SOLID Swift - Apple Best Practices 2026
Agent Workflow (MANDATORY)
Before ANY implementation, spawn 3 agents in parallel, one Agent call each with a name:
- fuse-ai-pilot:explore-codebase - Analyze existing architecture
- fuse-ai-pilot:research-expert - Verify Swift/Apple docs via Apple Docs MCP + Context7
- XcodeBuildMCP - Build validation after code changes. Then run fuse-ai-pilot:sniper.
DRY - Reuse Before Creating (MANDATORY)
Before writing ANY new code:
- Grep the codebase for similar protocols, services, or logic
- Check shared locations:
Core/Extensions/, Core/Utilities/, Core/Protocols/
- If similar code exists -> extend/reuse instead of duplicate
- If code will be used by 2+ features -> create it in
Core/ directly
Architecture (Features Modular MANDATORY)
| Layer |
Location |
Max Lines |
| Views |
Features/[Feature]/Views/ |
80 |
| ViewModels |
Features/[Feature]/ViewModels/ |
100 |
| Services |
Features/[Feature]/Services/ |
100 |
| Protocols |
Features/[Feature]/Protocols/ |
30 |
| Shared |
Core/{Models,Protocols,Services,Extensions,Utilities}/ |
- |
NEVER use flat Sources/ structure - always Features/[Feature]/
Critical Rules (MANDATORY)
| Rule |
Value |
| File limit |
100 lines (split at 90) |
| ViewModels |
@MainActor @Observable |
| Protocols |
Features/[Feature]/Protocols/ or Core/Protocols/ ONLY |
| Models |
Sendable structs |
| Documentation |
/// on all public APIs |
| Previews |
Every View MUST have #Preview |
Reference Guide
Concepts
| Topic |
Reference |
When to consult |
| SOLID Overview |
solid-principles.md |
Quick reference all principles |
| SRP |
single-responsibility.md |
Fat views/VMs, splitting files |
| OCP |
open-closed.md |
Adding providers, extensibility |
| LSP |
liskov-substitution.md |
Protocol contracts, testing |
| ISP |
interface-segregation.md |
Fat protocols, splitting |
| DIP |
dependency-inversion.md |
Injection, testing, mocking |
| Concurrency |
concurrency-patterns.md |
Actors, @MainActor, Sendable |
| Anti-Patterns |
anti-patterns.md |
Code smells detection |
Templates
| Template |
When to use |
| view.md |
SwiftUI View with subviews and #Preview |
| viewmodel.md |
@Observable ViewModel with @MainActor |
| service.md |
API Service, Mock, Cache actor |
| protocol.md |
Service protocol, CQRS, Auth |
| model.md |
Model, DTO, Error, Enum |
Forbidden
| Anti-Pattern |
Fix |
| Files > 100 lines |
Split at 90 |
| Protocols in impl files |
Move to Protocols/ directory |
ObservableObject |
Use @Observable |
| Completion handlers |
Use async/await |
Missing #Preview |
Add preview for every View |
| Non-Sendable in async |
Use struct with let |
Flat Sources/ structure |
Use Features/[Feature]/ |
1---2name: solid-swift3description: Use when applying SOLID principles to Swift 6/SwiftUI code — file-size limits, protocol separation, @Observable, actors, feature-modular architecture.4---56<objective>7Enforces SOLID and DRY principles for Swift 6 and SwiftUI (iOS 26+) projects: a mandatory Features/[Feature]/ modular directory structure (never a flat Sources/ layout), strict file-size limits (100 lines, split at 90, with per-layer budgets for Views/ViewModels/Services/Protocols), protocols separated into their own Protocols/ directories, @Observable + @MainActor for ViewModels, Sendable structs for models, and mandatory #Preview on every View.89Covers all five SOLID principles with dedicated references (SRP, OCP, LSP, ISP, DIP), concurrency patterns (actors, @MainActor, Sendable), an anti-pattern catalog, and code templates for views, view models, services, protocols, and models.1011Requires grepping the codebase for reusable protocols/services before writing new code, and checking shared locations (Core/Extensions/, Core/Utilities/, Core/Protocols/) before duplicating logic used by 2+ features.12</objective>1314# SOLID Swift - Apple Best Practices 20261516## Agent Workflow (MANDATORY)1718Before ANY implementation, spawn 3 agents in parallel, one `Agent` call each with a `name`:19201. **fuse-ai-pilot:explore-codebase** - Analyze existing architecture212. **fuse-ai-pilot:research-expert** - Verify Swift/Apple docs via Apple Docs MCP + Context7223. **XcodeBuildMCP** - Build validation after code changes. Then run **fuse-ai-pilot:sniper**.2324---2526## DRY - Reuse Before Creating (MANDATORY)2728**Before writing ANY new code:**291. **Grep the codebase** for similar protocols, services, or logic302. Check shared locations: `Core/Extensions/`, `Core/Utilities/`, `Core/Protocols/`313. If similar code exists -> extend/reuse instead of duplicate324. If code will be used by 2+ features -> create it in `Core/` directly3334---3536## Architecture (Features Modular MANDATORY)3738| Layer | Location | Max Lines |39|-------|----------|-----------|40| Views | `Features/[Feature]/Views/` | 80 |41| ViewModels | `Features/[Feature]/ViewModels/` | 100 |42| Services | `Features/[Feature]/Services/` | 100 |43| Protocols | `Features/[Feature]/Protocols/` | 30 |44| Shared | `Core/{Models,Protocols,Services,Extensions,Utilities}/` | - |4546**NEVER use flat `Sources/` structure - always `Features/[Feature]/`**4748---4950## Critical Rules (MANDATORY)5152| Rule | Value |53|------|-------|54| File limit | 100 lines (split at 90) |55| ViewModels | `@MainActor @Observable` |56| Protocols | `Features/[Feature]/Protocols/` or `Core/Protocols/` ONLY |57| Models | `Sendable` structs |58| Documentation | `///` on all public APIs |59| Previews | Every View MUST have `#Preview` |6061---6263## Reference Guide6465### Concepts6667| Topic | Reference | When to consult |68|-------|-----------|-----------------|69| **SOLID Overview** | [solid-principles.md](references/solid-principles.md) | Quick reference all principles |70| **SRP** | [single-responsibility.md](references/single-responsibility.md) | Fat views/VMs, splitting files |71| **OCP** | [open-closed.md](references/open-closed.md) | Adding providers, extensibility |72| **LSP** | [liskov-substitution.md](references/liskov-substitution.md) | Protocol contracts, testing |73| **ISP** | [interface-segregation.md](references/interface-segregation.md) | Fat protocols, splitting |74| **DIP** | [dependency-inversion.md](references/dependency-inversion.md) | Injection, testing, mocking |75| **Concurrency** | [concurrency-patterns.md](references/concurrency-patterns.md) | Actors, @MainActor, Sendable |76| **Anti-Patterns** | [anti-patterns.md](references/anti-patterns.md) | Code smells detection |7778### Templates7980| Template | When to use |81|----------|-------------|82| [view.md](references/templates/view.md) | SwiftUI View with subviews and #Preview |83| [viewmodel.md](references/templates/viewmodel.md) | @Observable ViewModel with @MainActor |84| [service.md](references/templates/service.md) | API Service, Mock, Cache actor |85| [protocol.md](references/templates/protocol.md) | Service protocol, CQRS, Auth |86| [model.md](references/templates/model.md) | Model, DTO, Error, Enum |8788---8990## Forbidden9192| Anti-Pattern | Fix |93|--------------|-----|94| Files > 100 lines | Split at 90 |95| Protocols in impl files | Move to `Protocols/` directory |96| `ObservableObject` | Use `@Observable` |97| Completion handlers | Use `async/await` |98| Missing `#Preview` | Add preview for every View |99| Non-Sendable in async | Use `struct` with `let` |100| Flat `Sources/` structure | Use `Features/[Feature]/` |