swift

Designs and reviews Swift APIs with type-safe models and explicit concurrency boundaries.

172|8|Updated Apr 13, 2026
One-click install
npx skills add https://github.com/margelo/react-native-skills --skill swift-margelo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift
Source: https://github.com/margelo/react-native-skills/tree/main/skills/swift
Command: npx skills add https://github.com/margelo/react-native-skills --skill swift-margelo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Swift codebases often accumulate hidden thread hops, optional-heavy data models, and bloated files that mix delegates, converters, and platform glue into one type. This Skill guides the design, implementation, and review of Swift APIs so invalid states become unrepresentable, concurrency models stay consistent, and files follow a strict one-type-per-file structure. ## Core Features & Use Cases - Type-Safe API Design: Replaces nullable field clusters with protocols, conforming structs, or enums with associated values so each state exposes only its valid fields. - Concurrency Discipline: Enforces choosing either Swift async/await with actors or an owned serial DispatchQueue per feature, banning DispatchQueue.sync, unstructured Task { @MainActor in ... } hops, and sleep-based race fixes. - File Organization Rules: Applies one top-level type per file, named Type+operation.swift extension files, and orchestration-only Hybrid*Factory files for Nitro Modules. - Use Case: When building a Swift-backed React Native Nitro Module that wraps AVFoundation camera APIs, use this Skill to model scanned-data variants as distinct types, expose queue-bound reads as Promise<T> methods via Promise.parallel(queue), and keep the factory file limited to preflight checks and session creation. ## Quick Start Use the swift skill to review my HybridDataScanner.swift implementation and redesign its API and threading model.

Frequently Asked Questions about swift

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design type-safe Swift APIs for scanned data?

Model each state as its own type instead of one struct with many optionals. Use a protocol with conforming structs like ScannedText and ScannedBarcode, or an enum with associated values, so fields like barcode and barcodeType are nonoptional on the variant where they are valid.

When should I use DispatchQueue versus async/await in Swift?

Choose one concurrency model per feature. Use Swift async/await, Task, and actors when the whole operation fits Swift concurrency; use a private serial DispatchQueue when Apple delegate APIs, C++ bridges, JS runtimes, or Nitro thread boundaries already revolve around queues.

Can Swift properties perform queue hops or hardware queries?

No. Properties should only expose cheap, immediately readable state. If a value requires a thread hop, session query, or fallible native operation, expose an async getter method or, in Nitro Modules, a Promise<T> method using Promise.parallel(queue).

Why is DispatchQueue.main.sync or queue.sync considered a bug?

Synchronous queue hops block the calling thread and can deadlock, especially in property getters and setters. Replace them with DispatchQueue.async, an async API boundary, or a Nitro Promise method so callers explicitly wait for queue-bound work.

How should Swift files be organized in a Nitro Module?

Keep one top-level type per file and never put extensions inside Hybrid* implementation files. Place conversions in named Type+operation.swift files, keep Hybrid*Factory.swift as orchestration only, and extract permission checks and platform glue into focused helper files.

When should I use locks like NSLock in Swift code?

Treat locks as a last resort after ruling out MainActor, serial queues, or immutable snapshots. If a lock is needed for a listener registry, mutate and snapshot under the lock, then unlock before invoking callbacks or calling into JS or Nitro.