
View Refactor
- 23 installs
- 4.9k repo stars
- Updated July 14, 2026
- openai/plugins
view-refactor restructures macOS SwiftUI views into stable desktop scenes.
About
The view-refactor skill refactors macOS SwiftUI views and scenes into stable structure when files grow unwieldy or AppKit bridges proliferate. It splits giant root views that silently own every desktop surface, preferring one stable split or window layout with local conditionals inside. Extraction rules keep scene-level state at the scene root, push visual subtrees into focused child views, and isolate AppKit representables behind narrow adapters. It avoids duplicating state between SwiftUI and AppKit layers and documents when AppKit escape hatches are justified versus replaceable with SwiftUI modifiers. Pair with swiftui-patterns for desktop affordances and window-management for chrome behavior. Output describes before structure, extracted components, state ownership map, and validation steps for navigation and restoration. only at the narrow edges where desktop behavior truly requires it. Break the app into meaningful scene roots: main window, settings, utility windows, inspectors, or menu bar extras.
- Splits oversized root views into focused child components.
- Keeps one stable split or window layout with local conditionals.
- Isolates AppKit representables behind narrow adapters.
- Maps scene-level versus view-local state ownership.
- Avoids duplicating state across SwiftUI and AppKit.
View Refactor by the numbers
- 23 all-time installs (skills.sh)
- +1 installs in the week ending Jul 26, 2026 (Skillselion tracking)
- Ranked #694 of 1,039 Mobile Development skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
view-refactor capabilities & compatibility
- Capabilities
- root view split extraction rules · appkit escape hatch guidance · state ownership mapping
- Use cases
- refactoring · frontend
- Platforms
- macOS
What view-refactor says it does
Do not let one giant root view silently own every desktop surface
Prefer one stable split or window layout with local conditionals inside it
npx skills add https://github.com/openai/plugins --skill view-refactorAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 23 |
|---|---|
| repo stars | ★ 4.9k |
| Last updated | July 14, 2026 |
| Repository | openai/plugins ↗ |
How do I split a large SwiftUI view without breaking scene state?
Refactor large macOS SwiftUI views into stable scenes with narrow AppKit escapes.
Who is it for?
macOS SwiftUI developers cleaning up large view files.
Skip if: Skip for greenfield views under a few hundred lines.
When should I use this skill?
User splits large views, tightens scene state, or narrows AppKit escapes.
What you get
Refactored view tree with clear state ownership and narrow AppKit bridges.
Files
View Refactor
Overview
Refactor macOS views toward small, explicit, stable scene and view types. Default to native SwiftUI for layout, selection, commands, and settings. Reach for AppKit only at the narrow edges where desktop behavior truly requires it.
Core Guidelines
1) Model scenes explicitly
- Break the app into meaningful scene roots: main window, settings, utility windows, inspectors, or menu bar extras.
- Do not let one giant root view silently own every desktop surface.
2) Keep a predictable file shape
- Follow this ordering unless the file already has a stronger local convention:
- Environment
private/publiclet@State/ other stored properties- computed
var(non-view) initbody- computed view builders / other view helpers
- helper / async functions
2b) Split files by responsibility
- For non-trivial apps, do not keep the full app, all views, models, stores, networking clients, process clients, and helpers in one Swift file.
- Accept a single Swift file only for tiny throwaway examples or snippets: roughly under 50 lines, one screen, no persistence, no networking/process client, and no reusable models.
- Use
App/<AppName>App.swiftfor the@mainapp andAppDelegateonly. - Keep
Views/ContentView.swiftfocused on root layout and composition; move feature UI into files such asViews/SidebarView.swift,Views/DetailView.swift, andViews/ComposerView.swift. - Move value types and selection enums into
Models/*.swift, stores intoStores/*.swift, app-server/network/process clients intoServices/*.swift, and small formatters/resolvers/extensions intoSupport/*.swift. - Keep files small and named after the primary type they contain.
3) Prefer dedicated subview types over many computed some View fragments
- Extract meaningful desktop sections like sidebar rows, detail panels, inspectors, or toolbar content into focused subviews.
- Keep computed
some Viewhelpers small and rare. - Pass explicit data, bindings, and actions into subviews instead of handing down the whole scene model.
4) Keep selection and layout stable
- Prefer one stable split or window layout with local conditionals inside it.
- Avoid top-level branch swapping between radically different roots when selection changes.
- Let the layout be constant; let state drive the content inside it.
5) Extract commands, toolbars, and actions out of body
- Do not bury non-trivial button logic inline.
- Do not mix command routing, menu state, and layout in the same block if they can be named clearly.
- Keep
bodyreadable as UI, not as a desktop view controller.
6) Use scene and app storage intentionally
- Use
@SceneStoragefor per-window ephemeral state when it truly helps restore the scene. - Use
@AppStoragefor durable preferences, not transient UI toggles that only matter in one window. - Keep scene-owned state close to the scene root.
7) Keep AppKit escape hatches narrow
- If a representable or
NSWindowbridge exists, isolate it behind a small wrapper or helper. - Do not let AppKit references spread through unrelated SwiftUI views.
- If the bridge starts owning the feature, re-evaluate the architecture.
8) Observation usage
- For
@Observablereference types on modern macOS targets, store them as@Statein the owning view. - Pass observables explicitly to children.
- On older deployment targets, fall back to
@StateObjectand@ObservedObjectwhere needed.
Workflow
1. Identify the current scene boundary and whether the file is trying to do too much. 2. Reorder the file into a predictable top-to-bottom structure. 3. Extract desktop-specific sections into dedicated subview types. 4. Stabilize the root layout around selection, scenes, and commands rather than top-level branching. 5. Move action logic, command routing, and toolbar behavior into named helpers or separate types. 6. Tighten any AppKit bridge so the imperative edge is small and explicit. 7. Keep behavior intact unless the request explicitly asks for structural and behavioral changes together.
Refactor Checklist
- Split oversized view files before adding more UI.
- Move pure models, identifiers, and selection enums out of view files.
- Move
Process,URLSession, app-server, and platform client code out of SwiftUI views intoServices/. - Keep
AppDelegateand the@mainapp entrypoint minimal. - Build after each major split so compile errors stay local.
Common Smells
- A root view that mixes window scaffolding, settings, toolbar code, command handling, and detail layout.
- A single app file that mixes app entrypoint, root layout, feature views, models, stores, service clients, and support extensions.
- iOS-style push navigation forced into a Mac sidebar-detail problem.
- Several booleans for mutually exclusive inspectors, sheets, or utility windows.
- AppKit objects passed through many SwiftUI layers without a clear ownership reason.
- Large computed view fragments standing in for real subviews.
Notes
- A good macOS refactor should make scene structure, selection flow, and command ownership obvious.
- When the problem is fundamentally a missing desktop pattern, use
swiftui-patterns. - When the problem is fundamentally a boundary with AppKit, use
appkit-interop.
interface:
display_name: "View Refactor"
short_description: "Refactor macOS SwiftUI views and scenes toward stable desktop structure"
default_prompt: "Use $view-refactor to split oversized macOS scenes, stabilize sidebar and selection structure, extract commands and toolbar logic, and keep AppKit escape hatches narrow."
Related skills
FAQ
What does view-refactor do?
view-refactor restructures macOS SwiftUI views into stable desktop scenes.
When should I use view-refactor?
User splits large views, tightens scene state, or narrows AppKit escapes.
Is this skill safe to install?
Review the Security Audits panel on this page before installing in production.