Swift logo

Swift

Organization
wendylabsinc
swift

Expert guidance on Swift best practices, patterns, and implementation. Use when developers mention: (1) Swift configuration or environment variables, (2) swift-log or logging patterns, (3) OpenTelemetry or swift-otel, (4) Swift Testing framework or @Test macro, (5) Foundation avoidance or cross-platform Swift, (6) platform-specific code organization, (7) Span or memory safety patterns, (8) non-copyable types (~Copyable), (9) API design patterns or access modifiers.

Overview

Publisherwendylabsinc
Repositoryclaude-skills
Skill nameswift
Stars
62
Forks
5
Bundled files
5
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 5 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by wendylabsinc on GitHub. Read the source before you install it.

Installation

Install the Swift AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/wendylabsinc/claude-skills/tree/main/swift
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wendylabsinc/claude-skills.git /tmp/claude-skills
mkdir -p .claude/skills
cp -r /tmp/claude-skills/swift .claude/skills/swift
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Swift in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Swift on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Swift is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Swift

Swift is a modern general-purpose programming language.

Reference Files

Load these files as needed for specific topics:

  • references/swift-configuration.md - Swift Configuration: reading config from environment variables, files, CLI arguments; provider hierarchy, namespacing, hot reloading, secret handling
  • references/swift-log.md - Swift Log logging API: log levels, structured logging, best practices for libraries, metadata, custom handlers
  • references/swift-otel.md - Swift OTel: OpenTelemetry backend for server apps (preferred for Linux); OTLP export for logs, metrics, tracing; framework integration
  • references/swift-testing.md - Swift Testing framework: @Test macro, #expect/#require assertions, traits, parameterized tests, test suites, parallel execution, XCTest migration
  • references/debugging.md - Debugging tips: Terminal UI on Linux (alternate screen buffer), GitHub Actions log analysis

Swift Testing Test Names

Prefer backtick-escaped, sentence-style test function names so the test description lives in the function name:

swift
@Test
func `does something very special in a certain edge case`() async throws {
    // ...
}

Use @Test("...") display names only when a separate display name is specifically needed.

Access Modifiers

Keep types and functions internal unless they need to be public for external use. This prevents accidental exposure of implementation details and makes access level errors easier to fix.

Member Organization

Sort members by visibility in this order:

  1. Public
  2. Internal
  3. Private

Public members should come first and be grouped by topic using // MARK: - ... sections that read like Apple API reference groups. Put an empty line both above and below every // MARK: - ... heading. Prefer present-progressive gerund phrases that describe the capability, such as:

swift
// MARK: - Working with Child Items

public func addChild(_ child: Child) { ... }

// MARK: - Managing Life-Cycle

public func start() async throws { ... }

Use visibility markers for non-public sections:

swift
// MARK: - Internal

internal func prepareStorage() { ... }

// MARK: - Private

private func rebuildIndex() { ... }

Do not mix internal or private helpers into public topic sections. If public API has only one obvious topic, there is no need for a // MARK: - <Topic> before the internal/private sections.

Protocol Conformance Organization

Choose conformance placement based on what the protocol means:

  • If the protocol represents an "is-a" relationship, declare the conformance inline with the type declaration.
    • Example: public enum BlahError: Error { ... }
  • If the protocol describes an ability of a type, typically an -able protocol, put the conformance in an extension at the bottom of the same file as the protocol.
    • Use a // MARK: - <ProtocolName> heading immediately before the extension.
swift
public struct Blah { ... }

// MARK: - Codable

extension Blah: Codable {
    // Codable-specific implementation
}

Foundation Avoidance Policy

Avoid Foundation in core library code when possible:

  • Foundation types (Data, Date, UUID, etc.) should be avoided in public APIs for libraries targeting:
    • Embedded Swift
    • Cross-platform consistency
    • Binary size reduction (FoundationEssentials is 15-40MB)
  • Use Swift standard library types instead:
    • [UInt8] instead of Data for byte buffers
    • ContinuousClock.Instant or custom types instead of Date
    • Byte-based initializers instead of UUID strings
  • Always use internal import Foundation or internal import FoundationEssentials, never public import
swift
#if canImport(FoundationEssentials)
    internal import FoundationEssentials
#else
    internal import Foundation
#endif

InternalImportsByDefault Feature

When using InternalImportsByDefault in Package.swift, all imports are internal by default unless explicitly marked with public import.

When to use public import:

  • When types from the imported module are exposed in public API (return types, parameters, protocol conformances)
  • Example: public import ServiceLifecycle when conforming to ServiceLifecycle.Service in a public type
  • Never use public import Foundation - keep Foundation internal

Platform-Specific File Organization

Use a +platform suffix convention for platform-specific implementations:

  • PlatformDeviceDiscovery+macos.swift - macOS implementation
  • PlatformDeviceDiscovery+linux.swift - Linux implementation
  • PlatformDeviceDiscovery+default.swift - Fallback for other platforms

When adding methods to a protocol, all platform files must be updated to maintain conformance.

Linux C Library Support

Support both Glibc and Musl for Linux compatibility:

swift
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#endif

Avoid Repetitive Code in Selection Logic

When selecting from multiple options with preference ordering, use sorting instead of multiple conditional blocks:

Bad - Repetitive:

swift
if !preferBluetooth {
    for interface in interfaces {
        if case .lan(let device) = interface {
            return .lan(device)
        }
    }
}
for interface in interfaces {
    if case .bluetooth(let device) = interface {
        return .bluetooth(device)
    }
}
if preferBluetooth {
    for interface in interfaces {
        if case .lan(let device) = interface {
            return .lan(device)
        }
    }
}

Good - Sort once, iterate once:

swift
let sorted = interfaces.sorted { a, b in
    if preferBluetooth {
        return a.type == "Bluetooth" && b.type != "Bluetooth"
    } else {
        return a.type == "LAN" && b.type != "LAN"
    }
}

for interface in sorted {
    switch interface {
    case .lan(let device): return .lan(device)
    case .bluetooth(let device): return .bluetooth(device)
    default: continue
    }
}

Memory Safety Patterns (Swift 6.2+)

Swift 6.2 introduces opt-in strict memory safety checking via .strictMemorySafety() in Package.swift.

Span Lifetime Constraints:

  • Span<T> is lifetime-dependent - it borrows the memory of its backing storage
  • Cannot cross async boundaries
  • Cannot escape closure scope
  • Cannot pass to async callbacks

Solution: Asymmetric API Design Use Span for parsing (read-only, synchronous, borrowed) and [UInt8] for writing (owned, can cross boundaries):

swift
public struct Characteristic<Value: Sendable>: Sendable {
    // Parsing uses Span - borrowed, synchronous access
    internal let parse: @Sendable (borrowing Span<UInt8>) throws -> Value

    // Writing uses [UInt8] - owned, can cross closure boundaries
    public typealias WithBytes = ([UInt8]) -> Void
    internal let write: @Sendable (Value) -> (WithBytes) -> Void
}

Safe Integer Loading from Bytes:

swift
// UNSAFE: unsafeLoad
return span.bytes.unsafeLoad(as: UInt64.self)

// SAFE: Manual byte-by-byte assembly
var value: UInt64 = 0
for i in 0..<8 {
    value |= UInt64(span[i]) << (i * 8)
}
return value

Span-Based Computed Properties with _read/_modify

With the LifetimeDependence experimental feature, computed properties can return non-escapable types like RawSpan and MutableRawSpan using _read and _modify accessors:

swift
// Enable in Package.swift:
swiftSettings: [
    .enableExperimentalFeature("LifetimeDependence"),
]

// Read-only span access
public var bytes: RawSpan {
    _read {
        var mapInfo = GstMapInfo()
        guard mapBuffer(&mapInfo) else { fatalError("Failed to map") }
        defer { unmapBuffer(&mapInfo) }
        yield RawSpan(_unsafeStart: mapInfo.data, byteCount: Int(mapInfo.size))
    }
}

// Mutable span access with Copy-on-Write
public var mutableBytes: MutableRawSpan {
    _read {
        fatalError("Cannot read mutableBytes")
    }
    _modify {
        // Ensure unique ownership before write (CoW)
        if !isKnownUniquelyReferenced(&storage) {
            storage = storage.copy()!
        }
        var mapInfo = GstMapInfo()
        guard mapBuffer(&mapInfo) else { fatalError("Failed to map") }
        defer { unmapBuffer(&mapInfo) }
        var span = MutableRawSpan(_unsafeStart: mapInfo.data, byteCount: Int(mapInfo.size))
        yield &span
    }
}

Known Compiler Issue (Swift 6.2.3): The LifetimeDependenceScopeFixup pass can crash when using span.withUnsafeBytes in certain contexts. Workaround: provide separate closure-based methods for C interop that don't go through the span accessor.

Non-Copyable Types

Use ~Copyable for move-only types that should not be duplicated:

swift
public struct ResourceHandle: ~Copyable {
    // Can only be moved, not copied
}

public struct ServiceRegistration: @unchecked Sendable, ~Copyable { ... }

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Swift AI skill do?

Expert guidance on Swift best practices, patterns, and implementation. Use when developers mention: (1) Swift configuration or environment variables, (2) swift-log or logging patterns, (3) OpenTelemetry or swift-otel, (4) Swift Testing framework or @Test macro, (5) Foundation avoidance or cross-platform Swift, (6) platform-specific code organization, (7) Span or memory safety patterns, (8) non-copyable types (~Copyable), (9) API design patterns or access modifiers.

Why use Swift on TypingMind?

Because you install it once and use it with any model. Swift is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Swift in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/wendylabsinc/claude-skills/tree/main/swift. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Swift?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Swift?

As many as you like. As long as a model supports skills, you can use Swift with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Swift AI skill free?

It is published on GitHub by wendylabsinc. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇