Skip to content

deonmenezes/mobile-app-skill / skills/swiftui-expert-skill

swiftui-expert-skill

Verified

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, iPhone tab sidebar, 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.

FileKindSize
SKILL.mdskill md11.4 KB
agents/openai.yamlconfig228 B
assets/logo-small.pngbinary29.0 KB
assets/logo.pngbinary389.5 KB
assets/logo.svgother2.0 KB
references/accessibility-patterns.mdmarkdown5.9 KB
references/animation-advanced.mdmarkdown11.2 KB
references/animation-basics.mdmarkdown6.7 KB
references/animation-transitions.mdmarkdown7.9 KB
references/charts-accessibility.mdmarkdown6.1 KB
references/charts.mdmarkdown16.8 KB
references/document-apps.mdmarkdown11.1 KB
references/environment-patterns.mdmarkdown7.1 KB
references/focus-patterns.mdmarkdown8.7 KB
references/image-optimization.mdmarkdown10.4 KB
references/iphone-duo.mdmarkdown7.4 KB
references/latest-apis.mdmarkdown24.8 KB
references/layout-best-practices.mdmarkdown20.6 KB
references/liquid-glass.mdmarkdown12.4 KB
references/list-patterns.mdmarkdown20.5 KB
references/localization.mdmarkdown9.7 KB
references/macos-scenes.mdmarkdown9.5 KB
references/macos-views.mdmarkdown10.8 KB
references/macos-window-styling.mdmarkdown8.6 KB
references/modifier-patterns.mdmarkdown2.5 KB
references/performance-patterns.mdmarkdown11.7 KB
references/previews.mdmarkdown8.1 KB
references/scroll-patterns.mdmarkdown10.6 KB
references/sheet-navigation-patterns.mdmarkdown15.0 KB
references/soft-deprecation.mdmarkdown2.9 KB
references/state-management.mdmarkdown21.5 KB
references/styled-text-editing.mdmarkdown8.7 KB
references/text-patterns.mdmarkdown1.6 KB
references/toolbar-patterns.mdmarkdown9.9 KB
references/trace-analysis.mdmarkdown14.1 KB
references/trace-recording.mdmarkdown5.8 KB
references/view-structure.mdmarkdown28.3 KB
references/webkit-integration.mdmarkdown9.5 KB
scripts/analyze_trace.pyscript9.9 KB
scripts/instruments_parser/__init__.pyscript69 B
scripts/instruments_parser/causes.pyscript5.9 KB
scripts/instruments_parser/correlate.pyscript6.2 KB
scripts/instruments_parser/events.pyscript10.6 KB
scripts/instruments_parser/hangs.pyscript3.4 KB
scripts/instruments_parser/hitches.pyscript4.5 KB
scripts/instruments_parser/summary.pyscript9.1 KB
scripts/instruments_parser/swiftui.pyscript6.6 KB
scripts/instruments_parser/time_profiler.pyscript4.3 KB
scripts/instruments_parser/xctrace.pyscript3.5 KB
scripts/instruments_parser/xml_utils.pyscript7.4 KB
scripts/record_trace.pyscript10.6 KB

scripts/instruments_parser/swiftui.py

View on GitHub
"""SwiftUI lane parser (Xcode 26+).

Primary schema is `swiftui-updates` with columns: start, duration, id,
update-type, allocations, description, category, view-hierarchy, module,
view-name, process, thread, root-causes, severity, cause-graph-node,
full-cause-graph-node.

We aggregate by view-name across all SwiftUI schemas (future-proofing against
schema renames) and break severity out separately so the agent can focus on
the high-severity rows.
"""
from __future__ import annotations

from collections import Counter, defaultdict
from pathlib import Path
from typing import Any

from . import xctrace, xml_utils

START_KEYS = ("start", "time", "sample-time", "timestamp")
DURATION_KEYS = ("duration", "body-duration", "update-duration")
VIEW_KEYS = ("view-name", "view", "view-type", "name", "type")
MODULE_KEYS = ("module",)
CATEGORY_KEYS = ("category",)
UPDATE_TYPE_KEYS = ("update-type",)
SEVERITY_KEYS = ("severity",)
DESCRIPTION_KEYS = ("description",)

HIGH_SEVERITIES = {"High", "Very High", "Severe", "Critical"}

# Ongoing / unterminated updates carry a sentinel duration (≈ UINT64_MAX-ish).
# Any duration longer than an hour is almost certainly that sentinel and would
# break aggregates + the correlation overlap check.
_SENTINEL_DURATION_NS = 60 * 60 * 1_000_000_000  # 1 hour


def analyze(
    trace_path: Path,
    toc_schemas: frozenset[str],
    top_n: int = 10,
    window: tuple[int, int] | None = None,
    run: int = 1,
) -> dict[str, Any]:
    schemas = sorted(
        s for s in toc_schemas
        if s.startswith("swiftui") and not s.endswith("-causes")
    )
    if not schemas:
        return {
            "lane": "swiftui",
            "available": False,
            "notes": ["SwiftUI lane not in trace (Xcode 26+ SwiftUI template required)."],
        }

    events: list[dict] = []
    per_view_total_ns: dict[str, int] = defaultdict(int)
    per_view_count: dict[str, int] = defaultdict(int)
    severity_counts: Counter[str] = Counter()
    update_type_counts: Counter[str] = Counter()
    category_counts: Counter[str] = Counter()

    for schema in schemas:
        xml_bytes = xctrace.export_schema(trace_path, schema, run=run)
        stream = xml_utils.RowStream(xml_bytes)
        for row in stream:
            start_ns = _first_int(row, stream, START_KEYS)
            dur_ns = _first_int(row, stream, DURATION_KEYS)
            if start_ns is None or dur_ns is None:
                continue
            if dur_ns < 0 or dur_ns > _SENTINEL_DURATION_NS:
                # Unterminated / ongoing update; skip so it doesn't poison
                # totals and the correlation overlap check.
                continue
            if not xml_utils.event_overlaps_window(start_ns, start_ns + dur_ns, window):
                continue

            view = _first_str(row, stream, VIEW_KEYS)
            module = _first_str(row, stream, MODULE_KEYS)
            category = _first_str(row, stream, CATEGORY_KEYS)
            update_type = _first_str(row, stream, UPDATE_TYPE_KEYS)
            severity = _first_str(row, stream, SEVERITY_KEYS)
            description = _first_str(row, stream, DESCRIPTION_KEYS)
            # Fall back through description → category → update-type so the
            # agent sees "EnvironmentWriter: RootEnvironment" instead of
            # "<unknown>" when SwiftUI doesn't record a view type.
            if not view:
                view = description or category or update_type or "<unknown>"

            per_view_total_ns[view] += dur_ns
            per_view_count[view] += 1
            if severity:
                severity_counts[severity] += 1
            if update_type:
                update_type_counts[update_type] += 1
            if category:
                category_counts[category] += 1

            events.append({
                "schema": schema,
                "start_ns": start_ns,
                "end_ns": start_ns + dur_ns,
                "duration_ns": dur_ns,
                "duration_ms": round(dur_ns / 1_000_000, 2),
                "start_ms": round(start_ns / 1_000_000, 2),
                "view": view,
                "module": module,
                "category": category,
                "update_type": update_type,
                "severity": severity,
                "description": description,
            })

    events.sort(key=lambda e: e["duration_ns"], reverse=True)

    top_by_total = sorted(
        per_view_total_ns.items(), key=lambda kv: kv[1], reverse=True
    )[:top_n]
    top_offenders = [
        {
            "view": view,
            "total_ms": round(total_ns / 1_000_000, 2),
            "count": per_view_count[view],
            "avg_ms": round(total_ns / per_view_count[view] / 1_000_000, 2),
        }
        for view, total_ns in top_by_total
    ]

    high_severity = [
        {
            "view": e["view"],
            "severity": e["severity"],
            "duration_ms": e["duration_ms"],
            "start_ms": e["start_ms"],
            "category": e["category"],
            "update_type": e["update_type"],
            "description": e["description"],
        }
        for e in events if e["severity"] in HIGH_SEVERITIES
    ][:top_n]

    longest = [
        {
            "view": e["view"],
            "duration_ms": e["duration_ms"],
            "start_ms": e["start_ms"],
            "category": e["category"],
            "update_type": e["update_type"],
            "severity": e["severity"],
        }
        for e in events[:top_n]
    ]

    return {
        "lane": "swiftui",
        "available": True,
        "schemas_used": schemas,
        "metrics": {
            "total_events": len(events),
            "unique_views": len(per_view_total_ns),
            "total_duration_ms": round(
                sum(per_view_total_ns.values()) / 1_000_000, 2
            ),
            "severity_breakdown": dict(severity_counts.most_common()),
            "update_type_breakdown": dict(update_type_counts.most_common()),
            "category_breakdown": dict(category_counts.most_common()),
        },
        "top_offenders": top_offenders,
        "longest_single_events": longest,
        "high_severity_events": high_severity,
        "notes": [],
        "_events": events,
    }


def _first_int(row, stream, keys):
    for key in keys:
        el = row.get(key)
        if el is None:
            continue
        val = xml_utils.int_text(stream.resolve(el))
        if val is not None:
            return val
    return None


def _first_str(row, stream, keys):
    for key in keys:
        el = row.get(key)
        if el is None:
            continue
        resolved = stream.resolve(el)
        txt = xml_utils.str_text(resolved) or resolved.get("fmt")
        if txt:
            return txt
    return None
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall