Unlock This Episode
Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.
Introduction
Brandon:
We now have two significant parts of the application using shared state: the list feature uses the @Shared
property wrapper to persist a collection of sync ups to disk whenever the data changes, and the detail feature uses @Shared
to express that it wants to make changes to a piece of state that are visible elsewhere. It’s awesome to see how everything hooks up to each other, and it’s very reminiscent of how bindings work in vanilla SwiftUI. In fact, we do like to think of @Shared
as being the Composable Architecture version of bindings from SwiftUI.
Stephen: So, this seems great, but how does it affect tests? We are now doing two things in our state that historically do not play nicely with testing. First, we have persistence, which means some interaction with the file system, which is a global blob of data that anyone can write to. And we have state sharing, which means a reference type is involved, and reference types are notoriously tricky to test since they don’t have a well-accepted notion of equality and since they cannot be copied.
Well, luckily our @Shared
property wrapper has none of these issues. It is completely testable, and even exhaustively testable.
Let’s take a look.
Subscribe to Point-Free
Access this episode, plus all past and future episodes when you become a subscriber.
Already a subscriber? Log in