And so this is absolutely incredible. We now have the basics of dedicated @Shared
property wrapper that allows us to easily share data between multiple features. And we’ve seen very concretely that this allows us to create complex features quite easily.
Now in doing this we did have to come face-to-face with what it means to put a reference type into our state. On the one hand it’s really no different than using a dependency to model shared state. Dependencies are very reference-like, even if they are modeled as structs, and so we used that fact to justify using a reference type directly in state. And thanks to Swift’s observation tools, reference types are now observable, and so everything just worked really nicely.
However, what is not going to be so nice about everything we have done so far is testing. Reference types are notoriously difficult to test because they are an amalgamation of data and behavior, and because they can’t be copied. This makes it difficult to compare the data inside a reference before and after a mutation has occurred so that we can assert on how it changed in an easy and exhaustive manner.
Let’s see these problems concretely, and then see how we might fix them.