Skip to content

buidangminh23/design-pro-max / skills/apple/.vendor/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
LICENSEother1.1 KB
SKILL.mdskill md11.4 KB
UPSTREAM.jsonconfig12.1 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/hitches.py

View on GitHub
"""Animation hitches lane parser.

Xcode 26 schema `hitches` columns: start, duration (hitch time), process,
is-system, swap-id, label, display, narrative-description. The
narrative-description field carries Apple's own attribution (e.g.
"Potentially expensive app update(s)") which is the highest-signal column.
"""
from __future__ import annotations

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

from . import xctrace, xml_utils

CANDIDATE_SCHEMAS = ("hitches", "animation-hitch", "hitch")

START_KEYS = ("start", "time", "sample-time")
DURATION_KEYS = ("duration", "hitch-duration", "frame-duration")


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]:
    schema = _pick_schema(toc_schemas)
    if schema is None:
        return {
            "lane": "hitches",
            "available": False,
            "notes": ["Animation hitches not present in trace."],
        }

    xml_bytes = xctrace.export_schema(trace_path, schema, run=run)
    stream = xml_utils.RowStream(xml_bytes)

    events: list[dict] = []
    narrative_counts: Counter[str] = Counter()
    system_count = 0

    for row in stream:
        start_ns = _first_int(row, stream, START_KEYS)
        duration_ns = _first_int(row, stream, DURATION_KEYS)
        if start_ns is None or duration_ns is None:
            continue
        if not xml_utils.event_overlaps_window(start_ns, start_ns + duration_ns, window):
            continue

        process_el = row.get("process")
        process = (
            xml_utils.extract_process(process_el, stream)
            if process_el is not None else None
        )

        narrative_el = row.get("narrative-description")
        narrative = xml_utils.str_text(stream.resolve(narrative_el)) if narrative_el is not None else None
        if narrative:
            narrative_counts[narrative] += 1

        is_system_el = row.get("is-system")
        is_system = _bool_text(stream.resolve(is_system_el)) if is_system_el is not None else None
        if is_system:
            system_count += 1

        events.append({
            "start_ns": start_ns,
            "end_ns": start_ns + duration_ns,
            "duration_ns": duration_ns,
            "hitch_duration_ns": duration_ns,  # Xcode 26 `duration` == hitch time
            "frame_duration_ns": None,
            "hitch_duration_ms": round(duration_ns / 1_000_000, 2),
            "frame_duration_ms": None,
            "start_ms": round(start_ns / 1_000_000, 2),
            "process": (process or {}).get("name"),
            "narrative": narrative,
            "is_system": bool(is_system) if is_system is not None else None,
        })

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

    total_hitch_ms = sum(e["hitch_duration_ms"] for e in events)
    worst = events[0] if events else None

    per_process: dict[str, int] = {}
    for e in events:
        key = e["process"] or "unknown"
        per_process[key] = per_process.get(key, 0) + 1

    top_offenders = [
        {
            "start_ms": e["start_ms"],
            "hitch_duration_ms": e["hitch_duration_ms"],
            "frame_duration_ms": e["frame_duration_ms"],
            "process": e["process"],
            "narrative": e["narrative"],
            "is_system": e["is_system"],
        }
        for e in events[:top_n]
    ]

    return {
        "lane": "hitches",
        "available": True,
        "schema_used": schema,
        "metrics": {
            "count": len(events),
            "total_hitch_ms": round(total_hitch_ms, 2),
            "worst_hitch_ms": worst["hitch_duration_ms"] if worst else 0,
            "per_process": per_process,
            "system_hitches": system_count,
            "app_hitches": len(events) - system_count,
            "narrative_breakdown": dict(narrative_counts.most_common()),
        },
        "top_offenders": top_offenders,
        "notes": [],
        "_events": events,
    }


def _pick_schema(available: frozenset[str]) -> str | None:
    for s in CANDIDATE_SCHEMAS:
        if s in available:
            return s
    return None


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 _bool_text(elem) -> bool | None:
    txt = xml_utils.str_text(elem)
    if txt is None:
        return None
    return txt.strip() in ("1", "true", "True", "YES", "Yes")
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: 472kUpdated 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