swiftui-debugging

swiftui-debugging is a skill for Claude Code, Codex from st0012/cctop. It costs 58 tokens per session (1,886 once invoked), scanned A, original, MIT.

A debugging guide for SwiftUI applications on macOS, covering stale views, layout issues, unnecessary redraws, state ownership, previews, and NSHostingView or NSPanel behavior.

In plain words
What is it for?
Use it to investigate views that do not update, layout and performance problems, state bugs, preview crashes, and macOS hosting-window issues.
Why use it?
SwiftUI may skip updates or hide diagnostic output when an app is launched from the command line or Finder. The guide provides ways to trace these problems, including file-based logging.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/st0012/cctop/swiftui-debugging
Any agent
npx skills add st0012/cctop --skill swiftui-debugging
Clone the repo
git clone --depth 1 https://github.com/st0012/cctop

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for swiftui-debugging

README.md
[![agentmods](https://agentmods.dev/badge/skills/st0012/cctop/swiftui-debugging.svg)](https://agentmods.dev/skills/st0012/cctop/swiftui-debugging)
Your own site
<a href="https://agentmods.dev/skills/st0012/cctop/swiftui-debugging"><img src="https://agentmods.dev/badge/skills/st0012/cctop/swiftui-debugging.svg" alt="Measured on agentmods" height="20"></a>
Per session 58 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,886 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00058 $0.01886
Opus 5 $0.00029 $0.00943
Sonnet 5 $0.00012 $0.00377
Haiku 4.5 $0.00006 $0.00189

Measured 3d ago against content hash 9bf78e7e72f5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

swiftui-debugging scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/swiftui-debugging/SKILL.md · 204 lines

How it starts

The opening of the file, as written. The whole thing — 204 lines — stays where its author put it; the contents beside it link to each section on GitHub.

SwiftUI Debugging

Overview

Systematic approaches for debugging SwiftUI issues in macOS apps. Covers view updates, state ownership, performance, layout, and macOS-specific quirks with NSHostingView and NSPanel.

Logging in macOS Apps

print() and NSLog() are invisible when launching macOS apps from CLI or Finder (menubar-only apps have no console). Always use file-based logging:

func debugLog(_ message: String) {
    let entry = "\(Date()) \(message)\n"
    let url = URL(fileURLWithPath: "/tmp/debug.log")
    if let handle = try? FileHandle(forWritingTo: url) {
        handle.seekToEndOfFile()
        handle.write(entry.data(using: .utf8)!)
        handle.closeFile()
    } else {
        try? entry.write(to: url, atomically: true, encoding: .utf8)
    }
}

Remove all debug logging before committing. Use grep -r "debugLog" --include="*.swift" to verify.

View Not Updating

Symptom

View shows stale data after a confirmed state change. Common with hostingView.rootView = NewView(...) not propagating to children, or theme/color changes not reflecting.

Root Cause: SwiftUI Diffing

SwiftUI skips re-evaluating a child view's body if the child's struct inputs haven't changed — even if the child reads from a singleton or computed property that did change.

Parent: rootView = MyView(counts: same)
  → SwiftUI: "counts didn't change, skip child body"
  → Child: never re-reads StatusColors.working
  → Result: stale colors

Diagnosis

  1. Log at the data source (model/manager) and at the view's body — confirm data changed but body wasn't called
  2. Check if the view reads external state (singletons, managers) not passed through its struct inputs
  3. Use Self._printChanges() at the top of body to see what SwiftUI thinks triggered (or didn't trigger) a re-evaluation

Fixes

Root Cause Fix
Child reads external state not in its inputs Pass a changing value and add .id(value) to force recreation
@State destroyed by .id() changes Extract into @StateObject owned by parent above the .id() boundary
NSColor(name:) dynamic colors cached Use .id() to force re-resolution
@Published changed but view doesn't update Verify view uses @ObservedObject, not a plain property

Read the full file on GitHub · 204 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 204 lines · 58 tokens per session scan A 9bf78e7e72f5

Subscribe to this mod's changes

swiftui-debugging is a skill published in the GitHub repository st0012/cctop (147 stars, last pushed 16d ago), licensed MIT. It adds 58 tokens to every session and 1,886 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

hns-lsel-curator

Local Self-Evolution Loop (LSEL) curator — the CLUSTER + drain engine for the GOOS-local PROPOSE→APPLY seam closure (SPEC-LSEL-LOCAL-EVOLUTION-001). Companion-offset drain of .moai/lessons-inbox.jsonl with a drain-side severity filter that drops the 65% Bash-timeout/sandbox noise, eventkey clustering with a frequency…

modu-ai/moai-adk · 135 tokens

hns-lsel-applier

Local Self-Evolution Loop (LSEL) APPLY engine — the playback-only consumer of approved decision.json records that drives .moai/hooks/lsel-apply.sh for the GOOS-local PROPOSE→APPLY seam closure (SPEC-LSEL-LOCAL-EVOLUTION-001 M3). Reads an approved decision.json, validates the target against the frozen allowlist…

modu-ai/moai-adk · 181 tokens

moai-workflow-ddd

Domain-Driven Development workflow specialist using ANALYZE-PRESERVE-IMPROVE cycle for behavior-preserving code transformation. Use when refactoring legacy code or reducing technical debt safely.

modu-ai/moai-adk · 44 tokens

hns-workflow-ci-loop

Unified CI watch + auto-fix loop skill. Polls gh pr checks after /moai sync PR creation, classifies required vs auxiliary failures, attempts safe automated patches (max 3 iterations), and escalates semantic failures to the user. Use for CI loop workflow — NOT for general loop iteration patterns (see…

modu-ai/moai-adk · 76 tokens

moai-kanban-foreman

One unattended kanban foreman iteration: watch the backlog queue, dispatch the next operator-picked card to an isolated worker, collect completion evidence on read (not on claims), and report. This is the body the project's loop.md driver invokes each iteration of a bare /loop; it can also be invoked directly to test…

modu-ai/moai-adk · 76 tokens

hns-moaiadk-patterns

Skill "hns-moaiadk-patterns" from modu-ai/moai-adk, covering moai-adk-go domain patterns, architecture quick reference, key source paths, pipeline specialist delegation map and template-first build cycle.

modu-ai/moai-adk · 116 tokens