1---2name: solid-swift3description: SOLID principles for Swift 6 and SwiftUI (iOS 26+). Files < 100 lines, protocols separated, @Observable, actors, Preview-driven development. Features Modular MANDATORY. Use when this capability is needed.4---56# SOLID Swift - Apple Best Practices 202678## Agent Workflow (MANDATORY)910Before ANY implementation, use `TeamCreate` to spawn 3 agents:11121. **fuse-ai-pilot:explore-codebase** - Analyze existing architecture132. **fuse-ai-pilot:research-expert** - Verify Swift/Apple docs via Apple Docs MCP + Context7143. **XcodeBuildMCP** - Build validation after code changes. Then run **fuse-ai-pilot:sniper**.1516---1718## DRY - Reuse Before Creating (MANDATORY)1920**Before writing ANY new code:**211. **Grep the codebase** for similar protocols, services, or logic222. Check shared locations: `Core/Extensions/`, `Core/Utilities/`, `Core/Protocols/`233. If similar code exists -> extend/reuse instead of duplicate244. If code will be used by 2+ features -> create it in `Core/` directly2526---2728## Architecture (Features Modular MANDATORY)2930| Layer | Location | Max Lines |31|-------|----------|-----------|32| Views | `Features/[Feature]/Views/` | 80 |33| ViewModels | `Features/[Feature]/ViewModels/` | 100 |34| Services | `Features/[Feature]/Services/` | 100 |35| Protocols | `Features/[Feature]/Protocols/` | 30 |36| Shared | `Core/{Models,Protocols,Services,Extensions,Utilities}/` | - |3738**NEVER use flat `Sources/` structure - always `Features/[Feature]/`**3940---4142## Critical Rules (MANDATORY)4344| Rule | Value |45|------|-------|46| File limit | 100 lines (split at 90) |47| ViewModels | `@MainActor @Observable` |48| Protocols | `Features/[Feature]/Protocols/` or `Core/Protocols/` ONLY |49| Models | `Sendable` structs |50| Documentation | `///` on all public APIs |51| Previews | Every View MUST have `#Preview` |5253---5455## Reference Guide5657### Concepts5859| Topic | Reference | When to consult |60|-------|-----------|-----------------|61| **SOLID Overview** | [solid-principles.md](references/solid-principles.md) | Quick reference all principles |62| **SRP** | [single-responsibility.md](references/single-responsibility.md) | Fat views/VMs, splitting files |63| **OCP** | [open-closed.md](references/open-closed.md) | Adding providers, extensibility |64| **LSP** | [liskov-substitution.md](references/liskov-substitution.md) | Protocol contracts, testing |65| **ISP** | [interface-segregation.md](references/interface-segregation.md) | Fat protocols, splitting |66| **DIP** | [dependency-inversion.md](references/dependency-inversion.md) | Injection, testing, mocking |67| **Concurrency** | [concurrency-patterns.md](references/concurrency-patterns.md) | Actors, @MainActor, Sendable |68| **Anti-Patterns** | [anti-patterns.md](references/anti-patterns.md) | Code smells detection |6970### Templates7172| Template | When to use |73|----------|-------------|74| [view.md](references/templates/view.md) | SwiftUI View with subviews and #Preview |75| [viewmodel.md](references/templates/viewmodel.md) | @Observable ViewModel with @MainActor |76| [service.md](references/templates/service.md) | API Service, Mock, Cache actor |77| [protocol.md](references/templates/protocol.md) | Service protocol, CQRS, Auth |78| [model.md](references/templates/model.md) | Model, DTO, Error, Enum |7980---8182## Forbidden8384| Anti-Pattern | Fix |85|--------------|-----|86| Files > 100 lines | Split at 90 |87| Protocols in impl files | Move to `Protocols/` directory |88| `ObservableObject` | Use `@Observable` |89| Completion handlers | Use `async/await` |90| Missing `#Preview` | Add preview for every View |91| Non-Sendable in async | Use `struct` with `let` |92| Flat `Sources/` structure | Use `Features/[Feature]/` |9394---95> Converted and distributed by [TomeVault](https://tomevault.io/claim/fusengine) — claim your Tome and manage your conversions.96<!-- tomevault:4.0:skill_md:2026-04-13 -->