All skills
avdlee avatar

/swiftui-expert-skill

@1e522cf

Use when writing, reviewing, or refactoring SwiftUI code for iOS or macOS, including state and `@Observable` data flow, view composition, resizable layouts, safe areas, display scale, performance, lists, environment, localization, animation, Liquid Glass, and API migration. Also use for iPhone Duo, foldable, or large-display layouts (`NavigationSplitView` on large displays, two-column reflow, foldable grids, `ArrangementView`, `ReservedRegion`), hinge effects, vertical bars, `@State` initialization or synthesized-property diagnostics, `@ContentBuilder` ambiguity, `reorderable` drag/drop, custom `AsyncImage` `URLSession`, swipe actions outside List, item-bound `alert`/`confirmationDialog`, `ToolbarOverflowMenu`, `AnimatableValues`, Document APIs (`Document`/`DocumentReader`), and Instruments `.trace` capture or analysis.

Use this Skill: https://skilld.dev/gh/avdlee/swiftui-agent-skill/swiftui-expert-skill

This session only. Nothing lands on disk.

referencestrace-recording.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Recording an Instruments Trace

Use this reference when the user asks to record a new trace — either to attach to a running app, launch one fresh, or capture a specific session of actions they'll perform interactively.

The bundled scripts/record_trace.py wraps xctrace record with:

  • The SwiftUI template by default (override with --template).
  • Manual stop via Ctrl+C, a stop-file, or --time-limit.
  • JSON discovery for devices and templates.
  • Normal Python exit codes so an agent can orchestrate.
  • Redacted command logging for values passed through --env.
  • An explicit acknowledgement gate for system-wide recordings.

Privacy and consent

Prefer --attach or --launch, which limits collection to the app being diagnosed. A system-wide recording can capture activity and metadata from unrelated applications. Before using --all-processes, explain that scope to the user and obtain their explicit approval. Then pass --allow-system-wide-recording to record that acknowledgement in the command.

Values passed through --env KEY=VALUE are forwarded to xctrace, but the wrapper redacts each value from its displayed command. Avoid placing secrets on command lines when a safer launch configuration is available, because other local process-inspection tools may still expose process arguments.

Typical flows

A) Attach to a running app on a connected device

python3 "${SKILL_DIR}/scripts/record_trace.py" \
  --device "Pol's iPhone" \
  --attach "Helm" \
  --output ~/Desktop/helm-session.trace

Leave it running while the user exercises the app. Stop with Ctrl+C.

B) Launch an app and record from the first frame

python3 "${SKILL_DIR}/scripts/record_trace.py" \
  --device "<UDID>" \
  --launch "/path/to/App.app" \
  --output ~/Desktop/launch.trace

Useful for diagnosing cold-start hitches and view-creation cost.

C) Agent-driven: start in background, stop via stop-file

When you (the agent) are running non-interactively — e.g. via Bash run_in_background — use a stop-file so you can signal the recording to end cleanly:

# Start recording (background)
python3 "${SKILL_DIR}/scripts/record_trace.py" \
  --attach Helm --stop-file /tmp/stop-trace \
  --output ~/Desktop/session.trace

# ...user does their thing...

# Stop cleanly (from another shell or tool call)
touch /tmp/stop-trace

The script polls every 0.5s for the stop-file, sends SIGINT to xctrace when it appears, and waits up to 60s for the trace to finalise.

D) Time-boxed recording

python3 "${SKILL_DIR}/scripts/record_trace.py" \
  --attach Helm --time-limit 30s --output ~/Desktop/30s.trace

xctrace stops itself at the limit.

Discovery helpers

# List every connected device, simulator, and the host — JSON.
python3 "${SKILL_DIR}/scripts/record_trace.py" --list-devices

# List all Instruments templates — JSON with a flat list + by-section map.
python3 "${SKILL_DIR}/scripts/record_trace.py" --list-templates

Device entries have kind (devices, devices offline, simulators), name, os, udid. Offline devices are known but unplugged / unpaired — plug them in before recording.

Picking a template

Hard rule: the SwiftUI template only populates the SwiftUI lane on a real device — a physical iOS/iPadOS device or the host Mac. On the iOS Simulator it records but the SwiftUI lane comes back empty. If the chosen UDID falls under the simulators kind from --list-devices, switch to Time Profiler. It still gives you Time Profiler + Hangs + Animation Hitches, which analyze_trace.py analyses and correlates normally; only the swiftui lane will report available: false.

Decision flow:

Target Template to pass
Physical iOS/iPadOS device (connected) SwiftUI (default)
Host Mac (macOS app, --all-processes, etc.) SwiftUI (default)
iOS / iPadOS / watchOS / tvOS Simulator Time Profiler

Always confirm the target kind with --list-devices before starting a recording: entries under simulators mean you must switch to Time Profiler; entries under devices (both connected devices and the host Mac) support the SwiftUI template. Entries under devices offline need the user to connect/unlock/trust the device before recording.

For ad-hoc hang hunting on any target, Time Profiler or Animation Hitches alone may be enough.

For an explicitly approved system-wide recording:

python3 "${SKILL_DIR}/scripts/record_trace.py" \
  --all-processes --allow-system-wide-recording \
  --time-limit 30s --output ~/Desktop/system-wide.trace

Chaining into analysis

The recording script prints trace written: <path> on exit. Feed that path straight into analyze_trace.py:

TRACE=$(python3 "${SKILL_DIR}/scripts/record_trace.py" \
    --attach Helm --stop-file /tmp/stop-trace --output ~/Desktop/session.trace \
    2>&1 | awk '/trace written:/ {print $NF}')
python3 "${SKILL_DIR}/scripts/analyze_trace.py" --trace "$TRACE" --json-only

If the user wanted a specific scope, combine with --list-logs / --list-signposts / --window from references/trace-analysis.md.

Failure modes to handle

  • Device offline — --list-devices shows it in devices offline. Ask the user to connect/unlock the device and retry.
  • Output path exists — the script refuses to overwrite. Either pick a new --output or delete the existing bundle.
  • App not running (for --attach) — xctrace exits with an error; fall back to --launch or tell the user to open the app first.
  • Signing / trust on device — iOS requires a development build signed with the user's team. If xctrace returns a signing error, point the user to trust the developer profile on the device.

Source: SKILL.md on GitHub

No alerts2d5 checks · Risk SAFE
  • Gen Agent Trust Hub2d

    The skill is a professional-grade assistant for SwiftUI development and performance profiling. It includes Python scripts to interface with the Xcode xctrace CLI for recording and analyzing Instruments traces. All identified code and instructions are consistent with its stated purpose and follow security best practices.

  • Socket2d

    No alerts

  • Snyk2d

    Risk: LOW · No issues

  • Runlayer6mo

    19 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 1e522cf. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 3 days ago
  • Performance
  • swiftui
  • ios
  • macos
  • instruments
  • state-management
  • view-composition
  • accessibility
  • animations

README badge

README badge for avdlee/swiftui-agent-skill/swiftui-expert-skill

Provides guidance for writing, reviewing, and refactoring SwiftUI code for iOS and macOS, including state management, view composition, performance optimization, and Instruments trace recording and analysis. Covers deprecated API detection, animation patterns, accessibility, and Liquid Glass adoption.

Generated from the current SKILL.md.

Does this skill work with both iOS and macOS?
Yes. The skill covers SwiftUI for both iOS and macOS, with dedicated reference sections for macOS-specific patterns like scenes, window styling, and views (HSplitView, Table, PasteButton).
Can this skill help me record and analyze Instruments traces?
Yes. The skill includes workflows to record traces via `record_trace.py` (with template selection for real devices vs simulators) and analyze them via `analyze_trace.py` to identify hangs, hitches, CPU hotspots, and excessive view updates.
Does this skill enforce a specific architecture pattern?
No. It focuses on correctness and performance without mandating MVVM, VIPER, or other architectural styles, though it encourages separating business logic from views for testability.
What does the skill do about deprecated APIs?
It consults `references/latest-apis.md` at the start of every task to identify and replace deprecated APIs with modern equivalents across iOS 15+ through iOS 26+, and gates version-specific APIs with `#available`.
Does this skill handle Liquid Glass effects?
Yes, but only when explicitly requested by the user. It includes guidance in `references/liquid-glass.md` for iOS 26+ Liquid Glass adoption with sensible fallbacks for earlier versions.

Generated from the current SKILL.md. These answers refresh after source changes.