Introducing a Swift Macro for Generating Protocol Witness Structs
The article introduces a new Swift macro that allows developers to generate protocol witness structs from classes and actors. Traditionally, developers have used protocols to express dependencies of classes in order to improve testability. However, this approach often leads to boilerplate code and limited flexibility. The new macro offers a solution by creating protocol witnesses, which are struct representations of protocols. These witnesses can be used to create multiple variations of a class without the need for additional types and boilerplate. In tests, developers can replace function implementations on a test-by-test basis. The article also acknowledges the limitations of this approach, particularly when it comes to managing mutable state. Overall, the macro provides a more flexible and efficient way to handle dependencies in Swift.