swiftui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSwiftUI Skill
SwiftUI 技能
When to Use This Skill
何时使用该技能
Use this skill when:
- Building user interfaces with SwiftUI
- Working with SwiftUI views, modifiers, and layouts
- Implementing state management with @State, @Binding, @ObservableObject
- Creating animations and transitions
- Implementing navigation with NavigationStack, NavigationLink, TabView
- Working with data flow patterns (@Environment, @EnvironmentObject)
- Using SwiftUI controls (Button, TextField, Picker, etc.)
- Building cross-platform apps for iOS, macOS, watchOS, tvOS, visionOS
在以下场景使用该技能:
- 使用SwiftUI构建用户界面
- 处理SwiftUI视图、修饰器和布局
- 使用@State、@Binding、@ObservableObject实现状态管理
- 创建动画与转场效果
- 使用NavigationStack、NavigationLink、TabView实现导航
- 处理数据流模式(@Environment、@EnvironmentObject)
- 使用SwiftUI控件(Button、TextField、Picker等)
- 为iOS、macOS、watchOS、tvOS、visionOS构建跨平台应用
Description
描述
Complete SwiftUI framework documentation covering views, modifiers, layout, state management, animations, navigation, data flow, and all SwiftUI APIs for iOS, macOS, watchOS, tvOS, and visionOS.
完整的SwiftUI框架文档,涵盖视图、修饰器、布局、状态管理、动画、导航、数据流,以及适用于iOS、macOS、watchOS、tvOS和visionOS的所有SwiftUI API。
Quick Reference
快速参考
Core Components
核心组件
Accessibility
无障碍访问
AccessibilityTraits
AccessibilityTraits
Animations
动画
AnimationAnyTransitionTransition
AnimationAnyTransitionTransition
Api Reference
API参考
CapsuleCircleCommandsConfirmationDialogDisclosureGroupEllipseForEachFormFullScreenCoverGaugeGeometryProxyGeometryReaderGroupBoxImmersiveSpaceListMenuMenuBarExtraObservedObjectOutlineGroupPublishedRectangleRoundedRectangleSectionSecureFieldSwiftUIToolbarToolbarItemToolbarItemGroup
CapsuleCircleCommandsConfirmationDialogDisclosureGroupEllipseForEachFormFullScreenCoverGaugeGeometryProxyGeometryReaderGroupBoxImmersiveSpaceListMenuMenuBarExtraObservedObjectOutlineGroupPublishedRectangleRoundedRectangleSectionSecureFieldSwiftUIToolbarToolbarItemToolbarItemGroup
App Structure
应用结构
DocumentGroupSceneSettingsWindowGroup
DocumentGroupSceneSettingsWindowGroup
Controls
控件
ButtonDatePickerPickerSliderStepperToggle
ButtonDatePickerPickerSliderStepperToggle
Data Flow
数据流
FocusedSceneValuePreferenceKey
FocusedSceneValuePreferenceKey
Drawing
绘图
CanvasPath
CanvasPath
Essentials
基础内容
AppAppStorage
AppAppStorage
Gestures
手势
DigitalCrownRotationalSensitivityDragGestureLongPressGestureMagnificationGestureRotationGestureTapGesture
DigitalCrownRotationalSensitivityDragGestureLongPressGestureMagnificationGestureRotationGestureTapGesture
Layout
布局
DividerGridGridRowHStackLazyHGridLazyHStackLazyVGridLazyVStackNavigationStackSpacerVStackZStack
DividerGridGridRowHStackLazyHGridLazyHStackLazyVGridLazyVStackNavigationStackSpacerVStackZStack
Navigation
导航
AlertLinkNavigationLinkNavigationPathPopoverSheetTableTableColumnWKInterfaceObjectRepresentable
AlertLinkNavigationLinkNavigationPathPopoverSheetTableTableColumnWKInterfaceObjectRepresentable
State Management
状态管理
BindingEnvironmentEnvironmentObjectFocusStateObservableObservableObjectSceneStorageStateStateObject
BindingEnvironmentEnvironmentObjectFocusStateObservableObservableObjectSceneStorageStateStateObject
Views
视图
AccessibilityLabelColorColorPickerContextMenuImageLabelNSViewControllerRepresentableNSViewRepresentablePreviewProviderProgressViewRealityViewScrollViewShapeTabViewTextTextEditorTextFieldTimelineViewUIViewControllerRepresentableUIViewRepresentableViewViewModifier
AccessibilityLabelColorColorPickerContextMenuImageLabelNSViewControllerRepresentableNSViewRepresentablePreviewProviderProgressViewRealityViewScrollViewShapeTabViewTextTextEditorTextFieldTimelineViewUIViewControllerRepresentableUIViewRepresentableViewViewModifier
Key Concepts
核心概念
Platform Support
平台支持
- iOS 26.0+
- iPadOS 26.0+
- macOS 26.0+
- Mac Catalyst 26.0+
- visionOS 26.0+
- iOS 26.0+
- iPadOS 26.0+
- macOS 26.0+
- Mac Catalyst 26.0+
- visionOS 26.0+
On-Device AI
设备端AI
All models run entirely on-device, ensuring privacy and offline capability.
所有模型完全在设备端运行,确保隐私性和离线使用能力。
Usage Guidelines
使用指南
- Check model availability before use
- Define clear instructions for the model's behavior
- Use guided generation for structured outputs
- Implement tool calling for dynamic capabilities
- Handle errors appropriately
- 使用前检查模型可用性
- 为模型行为定义清晰的指令
- 使用引导生成来获取结构化输出
- 实现工具调用以获得动态能力
- 妥善处理错误
Navigation
导航
See the directory for detailed API documentation organized by category:
references/- - Accessibility
references/accessibility.md - - Animations
references/animations.md - - Api Reference
references/api_reference.md - - App Structure
references/app_structure.md - - Controls
references/controls.md - - Data Flow
references/data_flow.md - - Drawing
references/drawing.md - - Essentials
references/essentials.md - - Gestures
references/gestures.md - - Layout
references/layout.md - - Navigation
references/navigation.md - - State Management
references/state_management.md - - View Modifiers (18 modifiers including .sheet(), .frame(), .animation(), etc.)
references/view_modifiers.md - - Views
references/views.md
请查看目录下按类别组织的详细API文档:
references/- - 无障碍访问
references/accessibility.md - - 动画
references/animations.md - - API参考
references/api_reference.md - - 应用结构
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 - - 视图修饰器(包含.sheet()、.frame()、.animation()等18种修饰器)
references/view_modifiers.md - - 视图
references/views.md
Best Practices
最佳实践
- Prompting: Be specific and clear in your prompts
- Instructions: Define the model's behavior upfront
- Safety: Enable guardrails for sensitive content
- Localization: Check supported languages for your use case
- Performance: Use prewarm() for better response times
- Streaming: Use streamResponse() for real-time user feedback
- 提示词: 提示词应具体清晰
- 指令: 预先定义模型的行为
- 安全性: 为敏感内容启用防护机制
- 本地化: 检查你的使用场景所支持的语言
- 性能: 使用prewarm()以获得更快的响应速度
- 流式传输: 使用streamResponse()以实现实时用户反馈
Common Patterns
常见模式
Basic Session
基础会话
swift
let model = SystemLanguageModel(useCase: .general)
let session = LanguageModelSession(model: model)
let response = try await session.respond(to: Prompt("Your question"))swift
let model = SystemLanguageModel(useCase: .general)
let session = LanguageModelSession(model: model)
let response = try await session.respond(to: Prompt("Your question"))Guided Generation
引导生成
swift
struct Recipe: Generable {
let title: String
let ingredients: [String]
}
let recipe = try await session.respond(
generating: Recipe.self,
prompt: Prompt("Create a pasta recipe")
)swift
struct Recipe: Generable {
let title: String
let ingredients: [String]
}
let recipe = try await session.respond(
generating: Recipe.self,
prompt: Prompt("Create a pasta recipe")
)Tool Calling
工具调用
swift
struct WeatherTool: Tool {
func call(arguments: String) async throws -> String {
// Fetch weather data
}
}
let session = LanguageModelSession(
model: model,
tools: [WeatherTool()]
)swift
struct WeatherTool: Tool {
func call(arguments: String) async throws -> String {
// Fetch weather data
}
}
let session = LanguageModelSession(
model: model,
tools: [WeatherTool()]
)Reference Documentation
参考文档
For complete API details, see the categorized documentation in the directory.
references/如需完整的API细节,请查看目录下的分类文档。
references/