Swift

Use when: write or review idiomatic Swift with value types, optionals, and safe concurrency.

kimtth 6f0e0eb 1.1 KB Updated

File contents

Goal: safe, expressive Swift that models intent with the type system.

Use for:

  • new Swift code for apps, libraries, or tools
  • reviewing optionals, value semantics, and concurrency
  • modernizing callback-heavy or force-unwrapped code

Workflow:

  1. Prefer structs and enums; reach for classes when identity matters.
  2. Handle optionals with if/guard let; avoid force unwraps.
  3. Model variants with enums and associated values.
  4. Use async/await and actors for concurrency safety.
  5. Express errors with throws and typed Error values.
  6. Verify with XCTest and the compiler's warnings.

Idioms:

  • guard for early exit and unwrapping
  • value types for predictable copy semantics
  • protocols with extensions for shared behavior
  • Result and throws over completion-handler error codes

Rules:

  • avoid force unwrap (!) outside proven invariants
  • prefer value types; use reference types intentionally
  • isolate mutable state with actors
  • keep optionals meaningful, not pervasive

kimtth/agent-skill-100-lines-or-less/tree/main/skills/swift commit 6f0e0eba4c

Frequently asked questions

npx skillmds@latest add kimtth/swift