Files
cattleTransportation/.cursor/rules/frameworks/swiftui.mdc
2025-11-04 09:38:19 +08:00

16 lines
641 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: 该规则解释了 SwiftUI 在 iOS、macOS、watchOS 和 tvOS 开发中的模式和最佳实践。
globs: **/*.swift
alwaysApply: false
---
# SwiftUI 规则
- 使用结构体struct创建视图并保持其小巧和专注
- 使用 @State 管理简单的视图本地状态
- 使用带有 @Published 的 @ObservableObject 管理共享状态
- 使用 @Binding 将可变状态传递给子视图
- 创建自定义 ViewModifiers 实现可复用的样式
- 使用环境对象environment objects进行依赖注入
- 对大型集合使用 LazyVStack 和 LazyHStack
- 将复杂的视图逻辑提取到单独的组件中