跳到正文
cccskills
免费在 GitHub 公开

swiftui-ui-patterns

Build or refactor SwiftUI screens using component examples for navigation, state, layouts, and controls. The skill guides screen composition, asynchronous loading, previews, and build checks while following existing project conventions and supported operating system versions.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Build and refactor SwiftUI UI with component patterns and examples. Use when shaping navigation, state, layouts, controls, or screen composition.

查看安装方法

适用场景

  • Set up tabs, navigation, and sheets in a new app
  • Refactor large screens into focused subviews
  • Clarify state ownership and dependency sharing
  • Implement loading states and verify previews

包含的文件(32)

  • SKILL.md7.2 KB
  • agents/openai.yaml221 B
  • references/app-wiring.md6.5 KB
  • references/async-state.md2.8 KB
  • references/components-index.md4.2 KB
  • references/controls.md1.6 KB
  • references/deeplinks.md1.7 KB
  • references/focus.md2.3 KB
  • references/form.md3.0 KB
  • references/grids.md1.8 KB
  • references/haptics.md2.0 KB
  • references/input-toolbar.md1.4 KB
  • references/lightweight-clients.md2.5 KB
  • references/list.md2.7 KB
  • references/loading-placeholders.md1.2 KB
  • references/macos-settings.md2.0 KB
  • references/matched-transitions.md1.6 KB
  • references/media.md2.0 KB
  • references/menu-bar.md2.2 KB
  • references/navigationstack.md4.2 KB
  • references/overlay.md1.2 KB
  • references/performance.md1.9 KB
  • references/previews.md1.6 KB
  • references/scroll-reveal.md5.2 KB
  • references/scrollview.md2.3 KB
  • references/searchable.md1.7 KB
  • references/sheets.md4.2 KB
  • references/split-views.md2.0 KB
  • references/tabview.md3.4 KB
  • references/theming.md1.7 KB
  • references/title-menus.md2.1 KB
  • references/top-bar.md1.3 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

SwiftUI UI Patterns

Quick start

Choose a track based on your goal:

Existing project

  • Identify the feature or screen and the primary interaction model (list, detail, editor, settings, tabbed).
  • Find a nearby example in the repo with rg "TabView\(" or similar, then read the closest SwiftUI view.
  • Apply local conventions: prefer SwiftUI-native state, keep state local when possible, and use environment injection for shared dependencies.
  • Choose the relevant component reference from references/components-index.md and follow its guidance.
  • If the interaction reveals secondary content by dragging or scrolling the primary content away, read references/scroll-reveal.md before implementing gestures manually.
  • Build the view with small, focused subviews and SwiftUI-native data flow.

New project scaffolding

  • Start with references/app-wiring.md to wire TabView + NavigationStack + sheets.
  • Add a minimal AppTab and RouterPath based on the provided skeletons.
  • Choose the next component reference based on the UI you need first (TabView, NavigationStack, Sheets).
  • Expand the route and sheet enums as new screens are added.

General rules to follow

  • Use modern SwiftUI state (@State, @Binding, @Observable, @Environment) and avoid unnecessary view models.
  • If the deployment target includes iOS 16 or earlier and cannot use the Observation API introduced in iOS 17, fall back to ObservableObject with @StateObject for root ownership, @ObservedObject for injected observation, and @EnvironmentObject only for truly shared app-level state.
  • Prefer composition; keep views small and focused.
  • Use async/await with .task and explicit loading/error states. For restart, cancellation, and debouncing guidance, read references/async-state.md.
  • Keep shared app services in @Environment, but prefer explicit initializer injection for feature-local dependencies and models. For root wiring patterns, read references/app-wiring.md.
  • Prefer the newest SwiftUI API that fits the deployment target and call out the minimum OS whenever a pattern depends on it.
  • Maintain existing legacy patterns only when editing legacy files.
  • Follow the project's formatter and style guide.
  • Sheets: Prefer .sheet(item:) over .sheet(isPresented:) when state represents a selected model. Avoid if let inside a sheet body. Sheets should own their actions and call dismiss() internally instead of forwarding onCancel/onConfirm closures.
  • Scroll-driven reveals: Prefer deriving a normalized progress value from scroll offset and driving the visual state from that single source of truth. Avoid parallel gesture state machines unless scroll alone cannot express the interaction.

State ownership summary

Use the narrowest state tool that matches the ownership model:

ScenarioPreferred pattern
Local UI state owned by one view@State
Child mutates parent-owned value state@Binding
Root-owned reference model on iOS 17+@State with an @Observable type
Child reads or mutates an injected @Observable model on iOS 17+Pass it explicitly as a stored property
Shared app service or configuration@Environment(Type.self)
Legacy reference model on iOS 16 and earlier@StateObject at the root, @ObservedObject when injected

Choose the ownership location first, then pick the wrapper. Do not introduce a reference model when plain value state is enough.

Cross-cutting references

  • In addition to the references below, use web search to consult current Apple Developer documentation when SwiftUI APIs, availability, or platform guidance may have changed.
  • references/navigationstack.md: navigation ownership, per-tab history, and enum routing.
  • references/sheets.md: centralized modal presentation and enum-driven sheets.
  • references/deeplinks.md: URL handling and routing external links into app destinations.
  • references/app-wiring.md: root dependency graph, environment usage, and app shell wiring.
  • references/async-state.md: .task, .task(id:), cancellation, debouncing, and async UI state.
  • references/previews.md: #Preview, fixtures, mock environments, and isolated preview setup.
  • references/performance.md: stable identity, observation scope, lazy containers, and render-cost guardrails.

Anti-patterns

  • Giant views that mix layout, business logic, networking, routing, and formatting in one file.
  • Multiple boolean flags for mutually exclusive sheets, alerts, or navigation destinations.
  • Live service calls directly inside body-driven code paths instead of view lifecycle hooks or injected models/services.
  • Reaching for AnyView to work around type mismatches that should be solved with better composition.
  • Defaulting every shared dependency to @EnvironmentObject or a global router without a clear ownership reason.

Workflow for a new SwiftUI view

  1. Define the view's state, ownership location, and minimum OS assumptions before writing UI code.
  2. Identify which dependencies belong in @Environment and which should stay as explicit initializer inputs.
  3. Sketch the view hierarchy, routing model, and presentation points; extract repeated parts into subviews. For complex navigation, read references/navigationstack.md, references/sheets.md, or references/deeplinks.md. Build and verify no compiler errors before proceeding.
  4. Implement async loading with .task or .task(id:), plus explicit loading and error states when needed. Read references/async-state.md when the work depends on changing inputs or cancellation.
  5. Add previews for the primary and secondary states, then add accessibility labels or identifiers when the UI is interactive. Read references/previews.md when the view needs fixtures or injected mock dependencies.
  6. Validate with a build: confirm no compiler errors, check that previews render without crashing, ensure state changes propagate correctly, and sanity-check that list identity and observation scope will not cause avoidable re-renders. Read references/performance.md if the screen is large, scroll-heavy, or frequently updated. For common SwiftUI compilation errors — missing @State annotations, ambiguous ViewBuilder closures, or mismatched generic types — resolve them before updating callsites. If the build fails: read the error message carefully, fix the identified issue, then rebuild before proceeding to the next step. If a preview crashes, isolate the offending subview, confirm its state initialisation is valid, and re-run the preview before continuing.

Component references

Use references/components-index.md as the entry point. Each component reference should include:

  • Intent and best-fit scenarios.
  • Minimal usage pattern with local conventions.
  • Pitfalls and performance notes.
  • Paths to existing examples in the current repo.

Adding a new component reference

  • Create references/<component>.md.
  • Keep it short and actionable; link to concrete files in the current repo.
  • Update references/components-index.md with the new entry.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Review charts, diagrams, and dashboards for accessibility, including color contrast, keyboard access, and text alternatives. Get specific guidance for preserving key findings in screen readers, static exports, and reduced-motion views.

中文简介正在准备中。当前显示英语简介。

  • Reviewing dashboard colors and keyboard access
  • Writing chart alt text and long descriptions
  • Preparing accessible figures for PDF reports
openai/plugins75012026年10月8日 更新

Give a photo collection a consistent look using Adobe tools to adjust color, tone, presets, and optional crops. Review a before-and-after sample before processing the full set, then receive links to the edited images.

中文简介正在准备中。当前显示英语简介。

  • Giving travel photos a consistent look
  • Unifying photos taken in mixed lighting
  • Applying a warm or cinematic style across a photo set
openai/plugins75012026年10月8日 更新

Visualize a logo, sketch, or design on products such as mugs, shirts, and business cards. Review a pilot image, generate a visually consistent set, and collect the results on a shareable Firefly Board.

中文简介正在准备中。当前显示英语简介。

  • Preview a logo on mugs and shirts
  • Turn a hand-drawn sketch into product mockups
  • Create consistent brand presentation images
openai/plugins75012026年10月8日 更新

Prepare images and videos for social platforms using Adobe tools. Create image crops that keep the subject in view, expand backgrounds when available, preview a full-set sample, and resize videos while preserving their aspect ratio.

中文简介正在准备中。当前显示英语简介。

  • Creating image variants for multiple social platforms
  • Cropping photos for Instagram Stories
  • Preparing LinkedIn images and YouTube thumbnails
openai/plugins75012026年10月8日 更新

Create flyers, social posts, business cards, and other visuals from Adobe Express templates. Choose a template, customize its text and background color, and receive a design link, with additional editing and export options depending on the available tools.

中文简介正在准备中。当前显示英语简介。

  • Creating an event flyer
  • Designing an Instagram post
  • Customizing business card text and colors
openai/plugins75012026年10月8日 更新

Turn an uploaded video into three highlight edits with Adobe Quick Cut. Choose a target length and style, then compare versions that feature different moments and download the ones you prefer.

中文简介正在准备中。当前显示英语简介。

  • Creating a short highlight video for social media
  • Condensing interview footage into a highlight reel
  • Comparing three edits with different moment selections
openai/plugins75012026年10月8日 更新

查看 openai 的全部技能

报告此技能的问题