# Tic Tac Toe in SwiftUI, Done Properly: Value-Type State, Win Detection and Minimax AI

DevFeed: [Tic Tac Toe in SwiftUI, Done Properly: Value-Type State, Win Detection and Minimax AI](<https://devfeed.tech/articles/tic-tac-toe-in-swiftui-done-properly-value-type-state-win-detection-and-minimax-ai-98773.md>)

Original publisher: [Read original article](<https://hackernoon.com/tic-tac-toe-in-swiftui-done-properly-value-type-state-win-detection-and-minimax-ai?source=rss>)

Author: Alok Singh

Published: 2026-10-24T00:47:11Z

Content type: article

Language: en

Sources: [HackerNoon](<https://devfeed.tech/sources/hackernoon.md>)

Topics: [SwiftUI](<https://devfeed.tech/topics/swiftui.md>), [Artificial Intelligence](<https://devfeed.tech/topics/ai.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>)

Tags: [accessibility](<https://devfeed.tech/tags/accessibility.md>), [ai](<https://devfeed.tech/tags/ai.md>), [ai-game-development](<https://devfeed.tech/tags/ai-game-development.md>), [alpha](<https://devfeed.tech/tags/alpha.md>), [animation](<https://devfeed.tech/tags/animation.md>), [api](<https://devfeed.tech/tags/api.md>), [app-store](<https://devfeed.tech/tags/app-store.md>), [apple](<https://devfeed.tech/tags/apple.md>), [beta](<https://devfeed.tech/tags/beta.md>), [board](<https://devfeed.tech/tags/board.md>), [game](<https://devfeed.tech/tags/game.md>), [game-development](<https://devfeed.tech/tags/game-development.md>), [ios](<https://devfeed.tech/tags/ios.md>), [minimax](<https://devfeed.tech/tags/minimax.md>), [minimax-ai](<https://devfeed.tech/tags/minimax-ai.md>), [mobile-app-development](<https://devfeed.tech/tags/mobile-app-development.md>), [mobile-game-development](<https://devfeed.tech/tags/mobile-game-development.md>), [published](<https://devfeed.tech/tags/published.md>), [rules](<https://devfeed.tech/tags/rules.md>), [state](<https://devfeed.tech/tags/state.md>), [stateobject](<https://devfeed.tech/tags/stateobject.md>), [swiftui](<https://devfeed.tech/tags/swiftui.md>), [swiftui-guide](<https://devfeed.tech/tags/swiftui-guide.md>), [tic-tac-toe](<https://devfeed.tech/tags/tic-tac-toe.md>), [type](<https://devfeed.tech/tags/type.md>), [value](<https://devfeed.tech/tags/value.md>), [view](<https://devfeed.tech/tags/view.md>)

## AI overview

The article recommends separating tic-tac-toe rules from the interface: a Swift value-type `Game` owns turns, legal moves, outcomes and undo, while a view model applies moves and SwiftUI renders state and forwards taps. Immutable moves let unit tests check wins, draws and invalid moves, and let a minimax opponent explore copied boards. The proposed AI searches perfect play, uses depth to favor faster wins and slower losses, and applies alpha-beta pruning; a skill parameter can mix in random moves for easier play. The article notes that the sample UI APIs require newer iOS versions than the cited app's iOS 12 support, so an iOS 12 interface would need UIKit or older-compatible alternatives. It presents minimax as a proposed extension, not a feature confirmed by the app listing.

## Source excerpt

The smallest game worth architecting: an immutable board, testable rules, a view that just renders state, and the classic AI you can bolt on in 40 lines