
Swift Protocol Di Testing
This teaches protocol-based dependency injection for Swift, the kind you actually need when testing file system operations, network calls, or iCloud sync without hitting real I/O. You define small, focused protocols for each external boundary (file reading, bookmark storage), inject them with default parameters so production code stays clean, and swap in mocks for tests. The pattern works well with actors and Sendable requirements. It's straightforward and avoids the common mistakes like creating giant protocols or mocking everything. If you're writing Swift code that needs deterministic tests for error paths or works across app, test, and preview contexts, this is the standard approach done right.
- skills.sh installs
- 5K
- GitHub stars
- 229.1K
- last updated
- Jul 14, 2026
Install
$ npx -y skills add affaan-m/everything-claude-code --skill swift-protocol-di-testing --agent claude-codeInstalls into .claude/skills of the current project.
Files
Swift Protocol-Based Dependency Injection for Testing
Patterns for making Swift code testable by abstracting external dependencies (file system, network, iCloud) behind small, focused protocols. Enables deterministic tests without I/O.
When to Activate
- Writing Swift code that accesses file system, network, or external APIs
- Need to test error handling paths without triggering real failures
- Building modules that work across environments (app, test, SwiftUI preview)
- Designing testable architecture with Swift concurrency (actors, Sendable)
Core Pattern
1. Define Small, Focused Protocols
Each protocol handles exactly one external concern.
// File system access
public protocol FileSystemProviding: Sendable {
func containerURL(for purpose: Purpose) -> URL?
}
// File read/write operations
public protocol FileAccessorProviding: Sendable {
func read(from url: URL) throws -> Data
func write(_ data: Data, to url: URL) throws
func fileExists(at url: URL) -> Bool
}
Sponsors
Details
- Repository
- github.com/affaan-m/everything-claude-code
- Categories
- Testing & QA, Mobile Development
More from affaan-m/everything-claude-code
All 256- Bun Runtime4.9K
- Nextjs Turbopack4.9K
- Plankton Code Quality4.9K
- Swift Concurrency 6 24.9K
- Visa Doc Translate4.9K
- Ai Regression Testing4.8K
- Architecture Decision Records4.8K
- Blueprint4.8K
- Everything Claude Code Conventions4.8K
- Exa Search4.8K
- Kotlin Testing4.8K
- Customs Trade Compliance4.7K
- Data Scraper Agent4.7K
- Documentation Lookup4.7K
- Enterprise Agent Ops4.7K
- Flutter Dart Code Review4.7K
- Inventory Demand Planning4.7K
- Kotlin Ktor Patterns4.7K
- Nanoclaw Repl4.7K
- Pytorch Patterns4.7K
- Ralphinho Rfc Pipeline4.7K
- Carrier Relationship Management4.6K
- Context Budget4.6K
- Crosspost4.6K