State machines are great tools to describe systems with a finite number of states. They are predictable and testable, which is something we praise for as developers. State machines can be defined in a pretty abstract way, which makes it a good candidate for a Domain Specific Language implementation. In this article, we will try to create a DSL that can describe state machines in Swift and use it in a feedback loop architecture.
Implementing an architecture within an application can be challenging. There are rules we can follow (SOLID, Clean Architecture) and patterns to guide us (MVVM, MVP, MVI, Redux, …) but sometimes, things we thought were well established deserve a step back.
Introducing Spin, a universal feedback loop system in Swift. A Feedback Loop is a system that is able to self-regulate by using the resulting value from its computations as the next input to itself, constantly adjusting this value according to given rules.