Protocol-based dependency injection for testable Swift code with focused abstractions and Swift Testing.
Works with
Define small, single-responsibility protocols for each external concern (file system, network, APIs) and provide default production implementations
Create mock implementations with configurable error properties to test failure paths deterministically without real I/O
Inject dependencies via default parameters so production code uses real implementations automatically while tests o
AI-first code editor with Composer
Before installing skills in Cursor, ensure your development environment meets these requirements:
node --versionswift-protocol-di-testingExecute the skills CLI command in your project's root directory to begin installation:
Fetches swift-protocol-di-testing from affaan-m/everything-claude-code and configures it for Cursor.
The CLI shows a list of agents. Use arrow keys and space to select Cursor:
Confirm successful installation by checking the skill directory location:
Restart Cursor to activate swift-protocol-di-testing. Access via /swift-protocol-di-testing in your agent's command palette.
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your environment. Always review source, verify the publisher, and test in isolation before production.
Submit your Claude Code skill and start earning
Automate repetitive workflows and reduce manual effort
Example
Generate reports, summarize documents, draft communications
Save 3-5 hours per week on routine tasks
Learn new skills, understand complex topics, get expert guidance
Example
Explain concepts, provide examples, suggest learning resources
Accelerate learning and skill development by 2x
Enhance output quality through reviews, suggestions, and refinements
Example
Review drafts, suggest improvements, catch errors
Improve work quality by 30-40% with less effort
0
total installs
0
this week
142.9K
GitHub stars
0
upvotes
Run in your terminal
0
installs
0
this week
142.9K
stars
Patterns for making Swift code testable by abstracting external dependencies (file system, network, iCloud) behind small, focused protocols. Enables deterministic tests without I/O.
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
}
// Bookmark storage (e.g., for sandboxed apps)
public protocol BookmarkStorageProviding: Sendable {
func saveBookmark(_ data: Data, for key: String) throws
func loadBookmark(for key: String) throws -> Data?
}
public struct DefaultFileSystemProvider: FileSystemProviding {
public init() {}
public func containerURL(for purpose: Purpose) -> URL? {
FileManager.default.url(forUbiquityContainerIdentifier: nil)
}
}
public struct DefaultFileAccessor: FileAccessorProviding {
public init() {}
public func read(from url: URL) throws -> Data {
try Data(contentsOf: url)
}
public func write(_ data: Data, to url: URL) throws {
try data.write(to: url, options: .atomic)
}
public func fileExists(at url: URL) -> Bool {
FileManager.default.fileExists(atPath: url.path)
}
}
public final class MockFileAccessor: FileAccessorProviding, @unchecked Sendable {
public var files: [URL: Data] = [:]
public var readError: Error?
public var writeError: Error?
public init() {}
public func read(from url: URL) throws -> Data {
if let error = readError { throw error }
guard let data = files[url] else {
throw CocoaError(.fileReadNoSuchFile)
}
return data
}
public func write(_ data: Data, to url: URL) throws {
if let error = writeError { throw error }
files[url] = data
}
public func fileExists(at url: URL) -> Bool {
files[url] != nil
}
}
Production code uses defaults; tests inject mocks.
public actor SyncManager {
private let fileSystem: FileSystemProviding
private let fileAccessor: FileAccessorProviding
public init(
fileSystem: FileSystemProviding = DefaultFileSystemProvider(),
fileAccessor: FileAccessorProviding = DefaultFileAccessor()
) {
self.fileSystem = fileSystem
self.fileAccessor = fileAccessor
}
public func sync() async throws {
guard let containerURL = fileSystem.containerURL(for: .sync) else {
throw SyncError.containerNotAvailable
}
let data = try fileAccessor.read(
from: containerURL.appendingPathComponent("data.json")
)
// Process data...
}
}
import Testing
@Test("Sync manager handles missing container")
func testMissingContainer() async {
let mockFileSystem = MockFileSystemProvider(containerURL: nil)
let manager = SyncManager(fileSystem: mockFileSystem)
await #expect(throws: SyncError.containerNotAvailable) {
try await manager.sync()
}
}
@Test("Sync manager reads data correctly")
func testReadData() Prerequisites
Time Estimate
15-45 minutes depending on use case complexity
Steps
Common Pitfalls
✓ Do
✗ Don't
💡 Pro Tips
✓ Use when
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
✗ Avoid when
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
affaan-m/everything-claude-code
affaan-m/everything-claude-code
affaan-m/everything-claude-code
affaan-m/everything-claude-code
affaan-m/everything-claude-code
affaan-m/everything-claude-code
Solid pick for teams standardizing on skills: swift-protocol-di-testing is focused, and the summary matches what you get after install.
Registry listing for swift-protocol-di-testing matched our evaluation — installs cleanly and behaves as described in the markdown.
swift-protocol-di-testing reduced setup friction for our internal harness; good balance of opinion and flexibility.
swift-protocol-di-testing fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
Useful defaults in swift-protocol-di-testing — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
Keeps context tight: swift-protocol-di-testing is the kind of skill you can hand to a new teammate without a long onboarding doc.
I recommend swift-protocol-di-testing for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
We added swift-protocol-di-testing from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
Useful defaults in swift-protocol-di-testing — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
swift-protocol-di-testing fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
showing 1-10 of 73