Loading...
Loading...
Choose and implement iOS architecture patterns (MVVM, TCA, Clean Architecture) based on feature complexity. Use when designing architecture for new features or refactoring existing code.
npx skill4agent add dagba/ios-mcp architecture-patterns| Complexity | Pattern | Use When |
|---|---|---|
| Simple | MV | Single screen, local state only |
| Medium | MVVM | 2-5 screens, business logic, network calls |
| Complex | TCA | State machines, side effects, complex flows |
| Enterprise | Clean | Multiple teams, maximum modularity |
1. Single screen + local state only?
→ MV (SwiftUI View + @State)
2. Business logic or shared state?
→ MVVM
3. Complex state transitions?
→ TCA
4. Multi-team, high modularity?
→ Clean Architecture@Observable@State private var viewModel@MainActor@Published@Observableprotocol AuthServiceProtocol {
func login(_ email: String, _ password: String) async throws -> User
}
@Observable
final class LoginViewModel {
private let authService: AuthServiceProtocol
var email = ""
var password = ""
var isLoading = false
init(authService: AuthServiceProtocol = AuthService()) {
self.authService = authService
}
@MainActor
func login() async {
isLoading = true
defer { isLoading = false }
try? await authService.login(email, password)
}
}
struct LoginView: View {
@State private var viewModel = LoginViewModel()
var body: some View {
Form {
TextField("Email", text: $viewModel.email)
SecureField("Password", text: $viewModel.password)
Button("Login") { Task { await viewModel.login() } }
.disabled(viewModel.isLoading)
}
}
}ReducerTestStorevip-clean-architecturereferences/mvvm-patterns.mdreferences/tca-guide.mdreferences/clean-architecture.md