🎉 End-of-year Sale! Save 25% when you subscribe today.

Tour of Sharing: File Storage: Part 2

Episode #308 • Dec 18, 2024 • Subscriber-Only

We close out our tour of the Sharing library by showing how easy it is to test code that uses the @Shared property wrapper without worrying about values bleeding between tests and the simulator. And we’ll take the “in-memory” shared key for a spin by building one final feature.

Previous episode
Tour of Sharing: File Storage: Part 2
Locked

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Sign in with GitHub

Introduction

Brandon

If there is one word I would use to describe what we have done so far it would be: “wow”.

In just one line of code we are expressing the idea of sharing a piece of state with the file system. Using @Shared with file storage looks almost identical to using @Shared with user defaults, but it works beautifully for more complex data types. Any change made to the shared state is automatically saved to disk, and if anyone else every saves data straight to that file, the @Shared state in the app will immediately update.

Stephen

But things get even better. Even though the @Shared property wrapper typically is interacting with outside systems that we do not control, such as user defaults and the file system, it was still built in a way that makes it possible to test any of your code using @Shared. And can be done so with no additional setup work too.

It’s amazing to see, so let’s write a very basic test for our feature.

Testing


References

Downloads

Sample code

Get started with our free plan

Our free plan includes 1 subscriber-only episode of your choice, access to 64 free episodes with transcripts and code samples, and weekly updates from our newsletter.

View plans and pricing