Skip to content

DandyLyons/TCACalc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Outdated Example

It should be noted that this example of TCA is outdated. Point free has since released newer versions and updates that improve upon this architecture. In particular, TCA now has support for native Swift observation, meaning the use of views like ViewStore is no longer necessary, and there are much easier ways to use TCA. For more information, have a look at the many valuable migration guides for TCA including:

  1. Migrating to 1.4: the @Reducer macro
  2. Migrating to 1.7: @ObservableState macro
  3. Migrating to 1.8: Simplify @Reducer macro.

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages