swiftui-expert-skill by avdlee/swiftui-agent-skill
npx skills add https://github.com/avdlee/swiftui-agent-skill --skill swiftui-expert-skill使用此技能来构建、审查或改进 SwiftUI 功能,确保正确的状态管理、优化的视图组合以及 iOS 26+ 的液态玻璃样式。优先使用原生 API、遵循苹果设计指南并采用注重性能的模式。此技能侧重于事实和最佳实践,不强制推行特定的架构模式。
references/latest-apis.md,以确保仅使用当前未弃用的 APIreferences/state-management.md)references/view-structure.md)references/performance-patterns.md)references/list-patterns.md)references/animation-basics.md、references/animation-transitions.md)广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
references/accessibility-patterns.md)references/charts.md;关于无障碍功能和回退策略,参见 references/charts-accessibility.md)references/macos-scenes.md、references/macos-window-styling.md、references/macos-views.md)references/liquid-glass.md)references/latest-apis.md,将任何已弃用的 API 替换为其现代等效项references/state-management.md)references/view-structure.md)references/performance-patterns.md)references/list-patterns.md)references/animation-basics.md、references/animation-transitions.md)Button 而非点击手势,为动态类型添加 @ScaledMetric(参见 references/accessibility-patterns.md)references/charts.md、references/charts-accessibility.md)references/macos-scenes.md、references/macos-window-styling.md、references/macos-views.md)UIImage(data:) 时,建议进行图像下采样(作为可选优化,参见 references/image-optimization.md)references/latest-apis.md,为目标部署版本仅使用当前未弃用的 APIreferences/state-management.md)references/view-structure.md)references/layout-best-practices.md)references/animation-basics.md、references/animation-transitions.md、references/animation-advanced.md)Button,添加无障碍分组和标签(参见 references/accessibility-patterns.md)references/charts.md;关于无障碍功能,参见 references/charts-accessibility.md)references/macos-scenes.md)、窗口样式(参见 references/macos-window-styling.md)以及 HSplitView、Table 等视图(参见 references/macos-views.md)references/liquid-glass.md)#available 对 iOS 26+ 功能进行可用性检查并提供回退方案@State 必须是 private 的;用于内部视图状态@Binding 仅当子视图需要修改父视图状态时使用@StateObject 用于视图创建对象时;@ObservedObject 用于注入对象时@Observable 类使用 @State;对需要绑定的注入可观察对象使用 @Bindablelet;对响应式读取使用 var + .onChange()@State 或 @StateObject —— 它们只接受初始值ObservableObject 不会传播更改 —— 直接传递嵌套对象;@Observable 可以很好地处理嵌套body 简单且纯粹(无副作用或复杂逻辑)@ViewBuilder 函数@ViewBuilder let content: Content 而非基于闭包的 content 属性@Observable 状态对象,以缩小更新/依赖范围onReceive、onChange、滚动处理程序中进行冗余状态更新LazyVStack/LazyHStackForEach 使用稳定的标识符(对于动态内容,切勿使用 .indices)ForEach 元素的视图数量恒定ForEach 中进行内联过滤(预过滤并缓存)AnyViewUIImage(data:) 时,建议进行图像下采样(作为可选优化)GeometryReader)Self._logChanges() 或 Self._printChanges() 来调试意外的视图更新Shape.path()、visualEffect、Layout 和 onGeometryChange 闭包可能不在主线程上运行 —— 捕获值而不是访问 @MainActor 状态.animation(_:value:)(不带 value 的已弃用版本作用范围太广)withAnimationoffset、scale、rotation)而非布局更改(frame)Animatable 实现必须具有显式的 animatableData(或在 iOS 26+ 上使用 @Animatable 宏)@Animatable 宏自动合成 animatableData;使用 @AnimatableIgnored 排除属性.phaseAnimator(iOS 17+).keyframeAnimator(iOS 17+).transaction(value:) 来重新执行Button 而非 onTapGesture(免费获得 VoiceOver 支持)@ScaledMetricaccessibilityElement(children: .combine) 对相关元素进行分组,以获得合并的标签accessibilityLabelaccessibilityRepresentation仅在用户明确请求时采用。
glassEffect、GlassEffectContainer 和玻璃按钮样式GlassEffectContainer 中.glassEffect().interactive()@Namespace 的 glassEffectID| 包装器 | 使用场景 |
|---|---|
@State | 内部视图状态(必须是 private) |
@Binding | 子视图修改父视图状态 |
@StateObject | 视图拥有一个 ObservableObject |
@ObservedObject | 视图接收一个 ObservableObject |
@Bindable | iOS 17+:需要绑定的注入 @Observable |
let | 来自父视图的只读值 |
var | 通过 .onChange() 监视的只读值 |
// 带回退的基本玻璃效果
if #available(iOS 26, *) {
content
.padding()
.glassEffect(.regular.interactive(), in: .rect(cornerRadius: 16))
} else {
content
.padding()
.background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 16))
}
// 分组的玻璃元素
GlassEffectContainer(spacing: 24) {
HStack(spacing: 24) {
GlassButton1()
GlassButton2()
}
}
// 玻璃按钮
Button("Confirm") { }
.buttonStyle(.glassProminent)
references/latest-apis.md)@State 属性是 private 的@Binding 仅用于子视图修改父视图状态的场景@StateObject 用于自有对象,@ObservedObject 用于注入对象@Observable 使用 @State,对注入对象使用 @Bindable@State 或 @StateObjectObservableObject(或直接传递给子视图)references/sheet-navigation-patterns.md).sheet(item:)references/scroll-patterns.md)ScrollViewReaderreferences/view-structure.md)@ViewBuilder let content: Content.compositingGroup() 在 .clipShape() 之前references/performance-patterns.md)body 保持简单纯粹(无副作用)body 中创建对象bodyreferences/list-patterns.md).indices)AnyViewreferences/layout-best-practices.md)references/animation-basics.md、references/animation-transitions.md、references/animation-advanced.md).animation(_:value:)withAnimationAnimatable 具有显式的 animatableData(或在 iOS 26+ 上使用 @Animatable 宏).transaction(value:) 来重新执行references/accessibility-patterns.md)Button 而非 onTapGesture@ScaledMetricaccessibilityElement(children:) 分组accessibilityRepresentationreferences/charts.md、references/charts-accessibility.md)import ChartsIdentifiable(或显式的 id: 键路径)Chart,而非单个标记SectorMark、选择、可滚动轴)已进行可用性检查LinePlot、AreaPlot 等绘图类型)已进行可用性检查Chart3D、SurfacePlot)已进行可用性检查.value() 标签foregroundStyle(by:)(而非手动为每个标记指定颜色)references/macos-scenes.md、references/macos-window-styling.md、references/macos-views.md)Settings 场景(而非自定义窗口)MenuBarExtra(而非 AppKit NSStatusItem)Commands / CommandGroup / CommandMenuTable 适配 iOS 上的紧凑尺寸类(第一列显示合并信息)defaultSize、windowResizability 和 frame(minWidth:minHeight:) 配置#if os(macOS) 条件语句中makeNSView/updateNSView 生命周期的 NSViewRepresentableNavigationSplitView(而非 HSplitView)HSplitView/VSplitView 保留用于 IDE 风格的平等窗格#available(iOS 26, *) 并提供回退方案GlassEffectContainer 中.glassEffect() 在布局/外观修饰符之后应用.interactive() 仅用于用户可交互元素references/latest-apis.md - 所有工作流程的必读内容。 按版本分段的已弃用到现代 API 转换指南(iOS 15+ 到 iOS 26+)references/state-management.md - 属性包装器和数据流references/view-structure.md - 视图组合、提取和容器模式references/performance-patterns.md - 性能优化技术和反模式references/list-patterns.md - ForEach 标识符、稳定性、Table(iOS 16+)和列表最佳实践references/layout-best-practices.md - 布局模式、与上下文无关的视图和可测试性references/accessibility-patterns.md - 无障碍特性、分组、动态类型和 VoiceOverreferences/animation-basics.md - 核心动画概念、隐式/显式动画、时序、性能references/animation-transitions.md - 过渡、自定义过渡、Animatable 协议references/animation-advanced.md - 事务、相位/关键帧动画(iOS 17+)、完成处理程序(iOS 17+)、@Animatable 宏(iOS 26+)references/charts.md - Swift Charts 标记、轴、选择、样式、组合和 Chart3D(iOS 26+)references/charts-accessibility.md - 图表无障碍功能(VoiceOver、音频图表、AXChartDescriptorRepresentable)、回退策略和 WWDC 会议references/sheet-navigation-patterns.md - 表单呈现、NavigationSplitView、Inspector 和导航模式references/scroll-patterns.md - ScrollView 模式和编程式滚动references/image-optimization.md - AsyncImage、图像下采样和优化references/liquid-glass.md - iOS 26+ 液态玻璃 APIreferences/macos-scenes.md - macOS 场景类型:Settings、MenuBarExtra、WindowGroup、Window、UtilityWindow、DocumentGroupreferences/macos-window-styling.md - macOS 窗口配置:工具栏样式、大小调整、定位、NavigationSplitView、Inspector、Commandsreferences/macos-views.md - macOS 视图和组件:HSplitView、VSplitView、Table、PasteButton、文件对话框、拖放、AppKit 互操作此技能侧重于事实和最佳实践,而非架构观点:
每周安装量
8.0K
代码仓库
GitHub 星标数
2.1K
首次出现
2026年1月24日
安全审计
安装于
codex6.8K
opencode6.6K
gemini-cli6.4K
github-copilot6.0K
amp5.3K
kimi-cli5.3K
Use this skill to build, review, or improve SwiftUI features with correct state management, optimal view composition, and iOS 26+ Liquid Glass styling. Prioritize native APIs, Apple design guidance, and performance-conscious patterns. This skill focuses on facts and best practices without enforcing specific architectural patterns.
references/latest-apis.md to ensure only current, non-deprecated APIs are usedreferences/state-management.md)references/view-structure.md)references/performance-patterns.md)references/list-patterns.md)references/animation-basics.md, references/animation-transitions.md)references/accessibility-patterns.md)references/charts.md; for accessibility and fallback strategies see references/charts-accessibility.md)references/macos-scenes.md, references/macos-window-styling.md, references/macos-views.md)references/liquid-glass.md)references/latest-apis.md to replace any deprecated APIs with their modern equivalentsreferences/state-management.md)references/view-structure.md)references/performance-patterns.md)references/list-patterns.md)references/animation-basics.md, references/animation-transitions.md)Button over tap gestures, add for Dynamic Type (see )references/latest-apis.md to use only current, non-deprecated APIs for the target deployment versionreferences/state-management.md)references/view-structure.md)references/layout-best-practices.md)references/animation-basics.md, references/animation-transitions.md, references/animation-advanced.md)Button for tappable elements, add accessibility grouping and labels (see )@State must be private; use for internal view state@Binding only when a child needs to modify parent state@StateObject when view creates the object; @ObservedObject when injected@State with @Observable classes; use @Bindable for injected observables needing bindingslet for read-only values; var + for reactive readsbody simple and pure (no side effects or complex logic)@ViewBuilder functions only for small, simple sections@ViewBuilder let content: Content over closure-based content properties@Observable state objects in lists to narrow update/dependency scopeonReceive, onChange, scroll handlersLazyVStack/LazyHStack for large listsForEach (never .indices for dynamic content)ForEach element.animation(_:value:) with value parameter (deprecated version without value is too broad)withAnimation for event-driven animations (button taps, gestures)offset, scale, rotation) over layout changes (frame) for performanceAnimatable implementations must have explicit animatableData (or use @Animatable macro on iOS 26+)@Animatable macro to auto-synthesize ; use to exclude propertiesButton over onTapGesture for tappable elements (free VoiceOver support)@ScaledMetric for custom numeric values that should scale with Dynamic TypeaccessibilityElement(children: .combine) for joined labelsaccessibilityLabel when default labels are unclear or missingaccessibilityRepresentation for custom controls that should behave like native onesOnly adopt when explicitly requested by the user.
glassEffect, GlassEffectContainer, and glass button stylesGlassEffectContainer.glassEffect() after layout and visual modifiers.interactive() only for tappable/focusable elementsglassEffectID with @Namespace for morphing transitions| Wrapper | Use When |
|---|---|
@State | Internal view state (must be private) |
@Binding | Child modifies parent's state |
@StateObject | View owns an ObservableObject |
@ObservedObject | View receives an ObservableObject |
// Basic glass effect with fallback
if #available(iOS 26, *) {
content
.padding()
.glassEffect(.regular.interactive(), in: .rect(cornerRadius: 16))
} else {
content
.padding()
.background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 16))
}
// Grouped glass elements
GlassEffectContainer(spacing: 24) {
HStack(spacing: 24) {
GlassButton1()
GlassButton2()
}
}
// Glass buttons
Button("Confirm") { }
.buttonStyle(.glassProminent)
references/latest-apis.md)@State properties are private@Binding only where child modifies parent state@StateObject for owned, @ObservedObject for injected@State with @Observable, @Bindable for injected@State or @StateObjectObservableObject avoided (or passed directly to child views)references/sheet-navigation-patterns.md).sheet(item:) for model-based sheetsreferences/scroll-patterns.md)ScrollViewReader with stable IDs for programmatic scrollingreferences/view-structure.md)@ViewBuilder let content: Content.compositingGroup() before .clipShape() on layered viewsreferences/performance-patterns.md)body kept simple and pure (no side effects)bodybodyreferences/list-patterns.md).indices)AnyView in list rowsreferences/layout-best-practices.md)references/animation-basics.md, references/animation-transitions.md, references/animation-advanced.md).animation(_:value:) with value parameterwithAnimation for event-driven animationsAnimatable has explicit animatableData (or @Animatable macro on iOS 26+).transaction(value:) for reexecutionreferences/accessibility-patterns.md)Button used instead of onTapGesture for tappable elements@ScaledMetric used for custom values that should scale with Dynamic TypeaccessibilityElement(children:)accessibilityRepresentation when appropriatereferences/charts.md, references/charts-accessibility.md)import Charts is present in files using chart typesIdentifiable (or explicit id: key path)Chart, not individual marksSectorMark, selection, scrollable axes) are availability-gatedLinePlot, AreaPlot) are availability-gatedChart3D, SurfacePlot) are availability-gated.value() labels used for axes and accessibilityreferences/macos-scenes.md, references/macos-window-styling.md, references/macos-views.md)Settings scene for preferences (not a custom window)MenuBarExtra for menu bar items (not AppKit NSStatusItem)Commands / CommandGroup / CommandMenu for menu bar menusTable adapts for compact size classes on iOS (first column shows combined info)defaultSize, windowResizability, and frame(minWidth:minHeight:)#available(iOS 26, *) with fallback for Liquid GlassGlassEffectContainer.glassEffect() applied after layout/appearance modifiers.interactive() only on user-interactable elementsreferences/latest-apis.md - Required reading for all workflows. Version-segmented guide of deprecated-to-modern API transitions (iOS 15+ through iOS 26+)references/state-management.md - Property wrappers and data flowreferences/view-structure.md - View composition, extraction, and container patternsreferences/performance-patterns.md - Performance optimization techniques and anti-patternsreferences/list-patterns.md - ForEach identity, stability, Table (iOS 16+), and list best practicesreferences/layout-best-practices.md - Layout patterns, context-agnostic views, and testabilityreferences/accessibility-patterns.md - Accessibility traits, grouping, Dynamic Type, and VoiceOverreferences/animation-basics.md - Core animation concepts, implicit/explicit animations, timing, performanceThis skill focuses on facts and best practices , not architectural opinions:
Weekly Installs
8.0K
Repository
GitHub Stars
2.1K
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex6.8K
opencode6.6K
gemini-cli6.4K
github-copilot6.0K
amp5.3K
kimi-cli5.3K
97,600 周安装
@ScaledMetricreferences/accessibility-patterns.mdreferences/charts.md, references/charts-accessibility.md)references/macos-scenes.md, references/macos-window-styling.md, references/macos-views.md)UIImage(data:) is used (as optional optimization, see references/image-optimization.md)references/accessibility-patterns.mdreferences/charts.md; for accessibility see references/charts-accessibility.md)references/macos-scenes.md), window styling (see references/macos-window-styling.md), and views like HSplitView, Table (see references/macos-views.md)references/liquid-glass.md)#available and provide fallbacks.onChange()@State or @StateObject — they only accept initial valuesObservableObject doesn't propagate changes — pass nested objects directly; @Observable handles nesting fineForEach (prefilter and cache)AnyView in list rowsUIImage(data:) is encountered (as optional optimization)GeometryReader)Self._logChanges() or Self._printChanges() to debug unexpected view updatesShape.path(), visualEffect, Layout, and onGeometryChange closures may run off the main thread — capture values instead of accessing @MainActor stateanimatableData@AnimatableIgnored.phaseAnimator for multi-step sequences (iOS 17+).keyframeAnimator for precise timing control (iOS 17+).transaction(value:) for reexecution@BindableiOS 17+: Injected @Observable needing bindings |
let | Read-only value from parent |
var | Read-only value watched via .onChange() |
foregroundStyle(by:) used for categorical series (not manual per-mark colors)#if os(macOS) conditionalsNSViewRepresentable with proper makeNSView/updateNSView lifecycleNavigationSplitView (not HSplitView) for sidebar-based navigationHSplitView/VSplitView reserved for IDE-style equal peer panesreferences/animation-transitions.md - Transitions, custom transitions, Animatable protocolreferences/animation-advanced.md - Transactions, phase/keyframe animations (iOS 17+), completion handlers (iOS 17+), @Animatable macro (iOS 26+)references/charts.md - Swift Charts marks, axes, selection, styling, composition, and Chart3D (iOS 26+)references/charts-accessibility.md - Charts accessibility (VoiceOver, Audio Graph, AXChartDescriptorRepresentable), fallback strategies, and WWDC sessionsreferences/sheet-navigation-patterns.md - Sheet presentation, NavigationSplitView, Inspector, and navigation patternsreferences/scroll-patterns.md - ScrollView patterns and programmatic scrollingreferences/image-optimization.md - AsyncImage, image downsampling, and optimizationreferences/liquid-glass.md - iOS 26+ Liquid Glass APIreferences/macos-scenes.md - macOS scene types: Settings, MenuBarExtra, WindowGroup, Window, UtilityWindow, DocumentGroupreferences/macos-window-styling.md - macOS window configuration: toolbar styles, sizing, positioning, NavigationSplitView, Inspector, Commandsreferences/macos-views.md - macOS views and components: HSplitView, VSplitView, Table, PasteButton, file dialogs, drag & drop, AppKit interop