Files
e-party-iOS/.cursor/rules/swift-tca-architecture-guidelines.mdc
edwinQQQ a0200c8859 feat: 添加项目基础文件和依赖管理
新增.gitignore、Podfile和Podfile.lock文件以管理项目依赖,添加README.md文件提供项目简介和安装步骤,创建NIMSessionManager、ClientConfig、LogManager和NetworkManager等管理类以支持网络请求和日志记录功能,更新AppDelegate和ContentView以集成NIM SDK和实现用户登录功能。
2025-05-29 16:14:28 +08:00

52 lines
1.4 KiB
Plaintext

---
description:
globs:
alwaysApply: true
---
# TCA Architecture Guidelines
- Use The Composable Architecture (TCA) for state management and side effect handling.
- Define reducers for each feature and use @Reducer annotation.
- Use stores to manage state.
- Follow unidirectional data flow (state -> view -> action -> reducer -> state).
- Use @State to manage local state and @ObservedObject or @EnvironmentObject to manage shared state.
- Make sure all side effects (such as network requests) are handled in reducers using Effects.
- Divide reducers by functionality and define a root reducer.
- Use Dependency Injection to manage external dependencies (such as network, database).
- Write tests for reducers to ensure correct state transitions.
## Feature Structure
Each feature must include:
1. A `State` struct
2. An `Action` enum
3. A `Reducer`
4. A `View` (if applicable)
## Naming Conventions
- Feature: `{{FeatureName}}Feature`
- State: `{{FeatureName}}Feature.State`
- Action: `{{FeatureName}}Feature.Action`
- Reducer: `{{FeatureName}}Feature.reducer`
## Example
```swift
struct CounterFeature {
struct State: Equatable {
var count = 0
}
enum Action: Equatable {
case increment
case decrement
}
static let reducer = Reducer<State, Action, Void> { state, action, _ in
switch action {
case .increment:
state.count += 1
return .none
case .decrement:
state.count -= 1
return .none
}
}
}