Skip to main content
The Tic-Tac-Toe example demonstrates how to build a complete game using TCA with a modular architecture that supports multiple UI frameworks (SwiftUI and UIKit).

Overview

This example shows how to:
  • Implement game logic in a pure reducer
  • Create reusable game components
  • Support multiple UI frameworks
  • Model game state with custom types
  • Handle win conditions and game flow

Implementation

Key Concepts

Custom State Types

The Three type provides a fixed-size array for the 3x3 board:
This ensures type safety - the board will always be 3x3.

Game Rules in State

Win conditions are computed from state:

Pure Game Logic

All game logic lives in the reducer:

Modular Architecture

The example is organized into focused modules:
  • GameCore - Game state and logic
  • GameSwiftUI - SwiftUI views
  • GameUIKit - UIKit views
  • AppCore - Root app navigation
  • LoginCore - Authentication feature
  • NewGameCore - Game setup
This structure makes it easy to:
  • Share logic across UI frameworks
  • Test features in isolation
  • Reuse components

Derived View State

Extensions compute view-specific state:

Testing

Multi-Framework Support

The same Game reducer powers both SwiftUI and UIKit views:
Both views:
  • Observe the same state
  • Send the same actions
  • Share identical business logic

Source Code

View the complete example in the TCA repository:

Next Steps