Browse Questions
  • Snapshot testing captures a reference image of a view and compares future runs against it.
  • TCA is an open-source architecture library by Point-Free.
  • Use a protocol for URLSession or inject a custom URLProtocol subclass that intercepts requests and returns fake responses without hitting the network.
  • The Repository pattern abstracts the data layer behind a protocol.

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) }
            }
        }
    }
}