关于 swiftui
面向 Apple 平台界面开发者的 SwiftUI 参考技能,按类别整理布局、状态、导航、动画等框架 API 文档。
主要功能
- 01视图与修饰符参考
- 02布局与导航指南
- 03状态和数据流说明
- 04动画与手势 API
- 05平台 API 分类
适用场景
- 01构建 SwiftUI 界面与布局
- 02实现状态驱动界面
- 03添加导航与转场
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ ios-agent/ iosagent.dev --skill swiftui安装后在 Claude Code 中输入/swiftui确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/accessibility.mdanimations.mdapi_reference.mdapp_structure.mdcontrols.mddata_flow.mddrawing.mdessentials.mdgestures.mdindex.mdintegration.mdlayout.mdnavigation.mdplatform_specific.mdpreviews.mdstate_management.mdview_modifiers.mdviews.md详细介绍
SwiftUI 技能
何时使用此技能
在以下情况下使用此技能:
- 使用 SwiftUI 构建用户界面
- 使用 SwiftUI 视图、修饰符和布局
- 使用 @State、@Binding、@ObservableObject 实现状态管理
- 创建动画和过渡效果
- 使用 NavigationStack、NavigationLink、TabView 实现导航
- 使用数据流模式(@Environment、@EnvironmentObject)
- 使用 SwiftUI 控件(Button、TextField、Picker 等)
- 构建适用于 iOS、macOS、watchOS、tvOS、visionOS 的跨平台应用
描述
涵盖视图、修饰符、布局、状态管理、动画、导航、数据流以及适用于 iOS、macOS、watchOS、tvOS 和 visionOS 的所有 SwiftUI API 的完整 SwiftUI 框架文档。
快速参考
核心组件
辅助功能
AccessibilityTraits
动画
AnimationAnyTransitionTransition
API 参考
CapsuleCircleCommandsConfirmationDialogDisclosureGroupEllipseForEachFormFullScreenCoverGaugeGeometryProxyGeometryReaderGroupBoxImmersiveSpaceListMenuMenuBarExtraObservedObjectOutlineGroupPublishedRectangleRoundedRectangleSectionSecureFieldSwiftUIToolbarToolbarItemToolbarItemGroup
应用结构
DocumentGroupSceneSettingsWindowGroup
控件
ButtonDatePickerPickerSliderStepperToggle
数据流
FocusedSceneValuePreferenceKey
绘图
CanvasPath
基础内容
AppAppStorage
手势
DigitalCrownRotationalSensitivityDragGestureLongPressGestureMagnificationGestureRotationGestureTapGesture
布局
DividerGridGridRowHStackLazyHGridLazyHStackLazyVGridLazyVStackNavigationStackSpacerVStackZStack
导航
AlertLinkNavigationLinkNavigationPathPopoverSheetTableTableColumnWKInterfaceObjectRepresentable
状态管理
BindingEnvironmentEnvironmentObjectFocusStateObservableObservableObjectSceneStorageStateStateObject
视图
AccessibilityLabelColorColorPickerContextMenuImageLabelNSViewControllerRepresentableNSViewRepresentablePreviewProviderProgressViewRealityViewScrollViewShapeTabViewTextTextEditorTextFieldTimelineViewUIViewControllerRepresentableUIViewRepresentableViewViewModifier
关键概念
平台支持
- iOS 26.0+
- iPadOS 26.0+
- macOS 26.0+
- Mac Catalyst 26.0+
- visionOS 26.0+
设备端 AI
所有模型均完全在设备端运行,确保隐私和离线使用能力。
使用指南
- 使用前检查模型是否可用
- 为模型的行为定义清晰的指令
- 使用引导式生成来获得结构化输出
- 实现工具调用以支持动态功能
- 妥善处理错误
导航
详细的 API 文档按类别整理在 references/ 目录中:
references/accessibility.md- 辅助功能references/animations.md- 动画references/api_reference.md- API 参考references/app_structure.md- 应用结构references/controls.md- 控件references/data_flow.md- 数据流references/drawing.md- 绘图references/essentials.md- 基础内容references/gestures.md- 手势references/layout.md- 布局references/navigation.md- 导航references/state_management.md- 状态管理references/view_modifiers.md- 视图修饰符(包含 18 个修饰符,包括 .sheet()、.frame()、.animation() 等)references/views.md- 视图
最佳实践
- 提示词:提示词要具体、清晰
- 指令:提前定义模型的行为
- 安全性:为敏感内容启用防护机制
- 本地化:检查是否支持适用于你的场景的语言
- 性能:使用 prewarm() 提升响应速度
- 流式传输:使用 streamResponse() 为用户提供实时反馈
常见模式
基本会话
let model = SystemLanguageModel(useCase: .general)
let session = LanguageModelSession(model: model)
let response = try await session.respond(to: Prompt("Your question"))
引导式生成
struct Recipe: Generable {
let title: String
let ingredients: [String]
}
let recipe = try await session.respond(
generating: Recipe.self,
prompt: Prompt("Create a pasta recipe")
)
工具调用
struct WeatherTool: Tool {
func call(arguments: String) async throws -> String {
// Fetch weather data
}
}
let session = LanguageModelSession(
model: model,
tools: [WeatherTool()]
)
参考文档
如需完整的 API 详情,请参阅 references/ 目录中的分类文档。
评论
支持 Markdown