ArchitectureMidMCQ
What is TCA (The Composable Architecture)?
Test your knowledge:
Explanation & Code
Answer:
TCA is an open-source architecture library by Point-Free. It structures apps around a unidirectional data flow: State, Action, Reducer, and Effect.
View → sends Action → Reducer → mutates State → View re-renders
↓
Effect (async work) → returns Action
Code Example:
import ComposableArchitecture
@Reducer
struct Counter {
struct State: Equatable {
var count = 0
}
enum Action {
case increment
case decrement
}
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .increment: state.count += 1; return .none
case .decrement: state.count -= 1; return .none
}
}
}
}
struct CounterView: View {
let store: StoreOf<Counter>
var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
HStack {
Button("-") { viewStore.send(.decrement) }
Text("\(viewStore.count)")
Button("+") { viewStore.send(.increment) }
}
}
}
}
Rate your understanding: