/TCACalc

A demonstration of a calculator app written in Swift using The Composable Architecture.

Primary LanguageSwiftMIT LicenseMIT

TCACalc

Welcome to TCACalc, an example of a calculator app implemented in TCA (The Composable Architecture), with a calculation engine implemented as a Finite State Machine.

Features

  • Animated Text View
  • Light/dark mode toggle
    • Introducing Night Mode: A black and red UI Appearance for better sleep.

Tech Stack

  • Architecture: TCA
    • I chose TCA because it is extremely easy to prototype, iterate, and test. Each TCA feature is composable because it only observes it's own state, and cannot accidentally mutate someone else's state.
    • The calculation engine is also implemented in TCA, but with an atypical approach, a Finite State Machine. An FSM is a system that can only possibly be in one of a limited number of possible states, and can only transition from one state to another.
  • SwiftUI
  • Modern Swift Concurrency
    • This app uses only modern concurrency tools such as async await.

Inspiration and Acknowledgements

  • Robert M. Vunabandi
    • Part way through implementing the calculation engine, I discovered that the logic of calculators is far more complex than I initially suspected. I began to suspect that it might be modeled as an FSM. This led me to find Vunabandi's fantastic article Designing A Calculator with FSM Logic which is essentially reverse-engineering the calculator logic of Apple's Calculator app as an FSM. This article was absolutely vital to the implementation of TCACalc's calculation engine.
  • This helpful discussion on how to implement an FSM in TCA.
  • David Khourshid - Infinitely Better UIs with Finite Automata

Roadmap

Feedback

Feedback is greatly appreciated. To share suggestions for improvement, please open an issue.