swift
Installation
SKILL.md
Swift
Use this skill for Swift code that needs strong API boundaries, predictable threading, and idiomatic Apple-platform integration. When the code is part of a Nitro Module, pair this with build-nitro-modules for generated specs, Promise mapping, and HybridObject constraints.
Workflow
- Read the local Swift code, generated protocols, and surrounding API shape before editing.
- Choose the public type model first: make invalid states unrepresentable where Swift can express them.
- Choose one concurrency model for the feature before writing implementation code.
- Keep synchronous properties and methods cheap, local, and nonblocking.
- Make queue hops, hardware/session negotiation, I/O, and fallible async work explicit in the API.
Type-Safe API Design
- Represent state variants with types, not nullable clusters. Use protocols plus conforming structs/classes when variants share a public contract, or use
enumwith associated values when the set is closed and value-like. - Keep related fields nonoptional on the same variant. If
barcodeandbarcodeTypeare meaningful only together, put both onScannedBarcode; do not make both optional on a generic scanned-data struct. - Use optionals only for real domain absence inside one state, not for expressing which state the object is in.
- Prefer compile-time flow over caller-side probing. If callers need repeated
if letchains to discover valid field combinations, the API shape is probably wrong.