swift-protocol-di-testing

swift-protocol-di-testing is a skill for Claude Code, Codex from TalissonVitorino/kmp-ios-skills. It costs 32 tokens per session (1,298 once invoked), scanned A, a copy of swift-protocol-di-testing, MIT.

A guide to dependency injection in Swift using small protocols, which let code use replaceable versions of file systems, networks, and other outside services.

In plain words
What is it for?
Use it to design testable Swift modules, mock failures and external services, support SwiftUI previews, and work safely with concurrent code.
Why use it?
It makes tests predictable by allowing them to use fake services instead of real files, networks, or external APIs.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to design testable Swift modules, mock failures and external services, support SwiftUI previews, and work safely with concurrent code.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/talissonvitorino/kmp-ios-skills/swift-protocol-di-testing
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add TalissonVitorino/kmp-ios-skills --skill swift-protocol-di-testing
Clone the repo
git clone --depth 1 https://github.com/TalissonVitorino/kmp-ios-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for swift-protocol-di-testing

README.md
[![agentmods](https://agentmods.dev/badge/skills/talissonvitorino/kmp-ios-skills/swift-protocol-di-testing/github.svg)](https://agentmods.dev/skills/talissonvitorino/kmp-ios-skills/swift-protocol-di-testing)
Your own site
<a href="https://agentmods.dev/skills/talissonvitorino/kmp-ios-skills/swift-protocol-di-testing"><img src="https://agentmods.dev/badge/skills/talissonvitorino/kmp-ios-skills/swift-protocol-di-testing/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for swift-protocol-di-testing

Your own site · 80×15
<a href="https://agentmods.dev/skills/talissonvitorino/kmp-ios-skills/swift-protocol-di-testing"><img src="https://agentmods.dev/badge/skills/talissonvitorino/kmp-ios-skills/swift-protocol-di-testing.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 32 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,298 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin 95% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00032 $0.01298
Opus 5 $0.00016 $0.00649
Sonnet 5 $0.00006 $0.00260
Haiku 4.5 $0.00003 $0.00130

Measured 7d ago against content hash 70bce6526695, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

swift-protocol-di-testing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

95% identical to swift-protocol-di-testing — 4 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

ios/swift-protocol-di-testing/SKILL.md · 192 lines

How it starts

The opening of the file, as written. The whole thing — 192 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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
}

// 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?
}

2. Create Default (Production) Implementations

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)
    }
}

3. Create Mock Implementations for Testing

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
    }
}

Read the full file on GitHub · 192 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago First seen · 192 lines · 32 tokens per session scan A 70bce6526695

Subscribe to this mod's changes

swift-protocol-di-testing is a skill published in the GitHub repository TalissonVitorino/kmp-ios-skills (12 stars, last pushed 16d ago), licensed MIT. It adds 32 tokens to every session and 1,298 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. It is 95% identical to swift-protocol-di-testing, differing in 4 lines, and is treated as a copy.

Related

Other skills, from other repositories

compose-multiplatform

Use when building one shared Compose UI in Kotlin across Android, iOS, and desktop — commonMain @Composables, expect/actual, source-set placement, native interop, multiplatform ViewModel/navigation/Koin. NOT a single-platform native build (that is kotlin-android / swift-ios), and NOT Dart/Flutter cross-platform UI…

ericrisco/rsc-harness · 80 tokens

cmp-upgrade

Migrate an existing Kotlin/Compose Multiplatform (CMP/KMP) project to the next PROVEN-GREEN dependency version set. Use this when the user wants to upgrade Kotlin, KSP, Compose Multiplatform, Room, AGP, Koin, or Ktor versions in a KMP project, bump their KMP dependencies, or asks "upgrade kotlin/compose/KMP versions"…

kvdm-co-pilot/create-cmp · 205 tokens

cmp-dev-client

Run a create-cmp Compose Multiplatform app's shared UI in a live desktop window with Compose Hot Reload — the daily dev loop. Use this when the user wants to run their CMP app on desktop, preview the app while developing, iterate on Compose UI without an emulator, or asks "run my CMP app on desktop", "hot reload…

kvdm-co-pilot/create-cmp · 139 tokens

cmp-test

Generate a regression test suite for a Compose Multiplatform app by OBSERVING it — read the running app's semantics tree as JSON via the cmp-inspector MCP (testTags, text, clickables, bounds, nav state), derive a test plan from what actually rendered, and write the tests into the app's shipped harness (Maestro flows…

kvdm-co-pilot/create-cmp · 159 tokens

cmp-preview

THE default UI feedback loop while building or editing ANY Compose Multiplatform screen — in a stamped app, use it DURING development, not only when asked: it renders the app's REAL screens headlessly in seconds (no device, no emulator, no manual Gradle) and tells you exactly what each edit changed, so you catch your…

kvdm-co-pilot/create-cmp · 273 tokens

cmp-qa-prep

Bring up the E2E harness for a Kotlin/Compose Multiplatform app — boot the Android emulator, install the debug build, run the Maestro smoke — or, simpler, run the verify lane, which does all three itself. Use this when the user wants to run E2E/device tests on their CMP/KMP app, "prep my KMP test environment", "smoke…

kvdm-co-pilot/create-cmp · 131 tokens