Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TCA’s Life Cycle Catch Up Tutorial

Avatar for ryota ryota
June 20, 2025
13

TCA’s Life Cycle Catch Up Tutorial

Point-Freeが開発した、TCA(swift-composable-architecture)を使ったことはありますか?

このスライドでは、TCAのライフサイクルについて、SwiftUIを使ったシンプルなコード例を交えながら解説します。
TCAに興味があり、これから学んでみたいという方に最適な内容です。ぜひご覧ください!

Have you ever used The Composable Architecture (TCA) from Point-Free?
This deck introduces the TCA lifecycle with simple code examples in SwiftUI.

If you're interested in learning TCA, this is for you!

Avatar for ryota

ryota

June 20, 2025
Tweet

Transcript

  1. import ComposableArchitecture @Reducer struct HogeFeature { @ObservableState struct State: Equatable

    { var count = 0 var number: String? } enum Action { case incrementButtonTapped } } 主なコードフローについて見ていく (超簡単 ver.) 5 1-0 1-0 - ComposableArchitectureをインポート - ObservableStateマクロをつけたStateを作成 - ユーザーの動線に基づく命名がなされたAction の作成
  2. import ComposableArchitecture @Reducer struct HogeFeature { var body: some ReducerOf<Self>

    { Reduce { state, action in switch action { case .incrementButtonTapped: count += 1 return .none } } } } 6 1-0 1-0 bodyの中にenumで定義したActionの中身を記載 していく `ReducerOf<Self>`がXcode26でエラー → `Reducer<State, Action>`で対応可 主なコードフローについて見ていく (超簡単 ver.)
  3. import ComposableArchitecture struct HogeView: View { let store: StoreOf<HogeFeature> var

    body: some: View { Button(“Sample Button”) { store.send(.writtenAction) } } } 主なコードフローについて見ていく 7 1-0 1-0 StoreOf<HogeFeature>引数にとる
  4. メリット 19 1-0 2-2 - ユーザーの行動動線ベースでのコーディング - 比較的理解しやすい - モジュール性

    - scopeやforEachなどでcomposableな設計が可能 - テストの容易性 - TestStoreと依存関係の差し替え(DI)が簡単 - Xcode26に対しての爆速対応がさすが - https://github.com/pointfreeco/swift-navigation/pull/289