How to get started with The Composable Architecture 📱

Hi 👋

What a year it has been for this newsletter!

I sent the very first email on January 31st, and now, 42 emails later, we’re already reaching the last email of the year.

I have a big thank you to all of you for your support throughout this year!

Enjoy your holiday season and I’ll see you all back in 2024 🥂

(picture from the amazing winter party at PhotoRoom)

Before we go into this last email of the year, I have a big thank you to my sponsor for a new week: Bitrise 🤖


Advertisement

Mobile DevOps Health Check - the first industry benchmarking tool

How well does your Mobile DevOps team perform?

Take the quick Mobile DevOps Health Check to find out how mature your team is and how you compare against the industry’s top-performing apps.

See how you compare to the industry


Sponsors like Bitrise really help me grow my content creation, so if you have time please make sure to check out their survey: it’s a direct support to my content creation ☺️


There’s a good chance that you’ve heard of The Composable Architecture (or TCA) at one point or another.

Even if, like me, you’ve never used it, this architecture pattern for building iOS apps has become so popular over the past years that you’re bound to have heard of it.

And maybe, also like me, you’ve been wondering what was the best way to get started if you wanted to learn how this architecture works? 🤨

As it turns out, learning TCA might be easier than you might think!

Because the creators of TCA did a great job of putting together a long tutorial that progressively introduces and explains all the key concepts.

So if you want to ramp up your TCA skills, I really recommend that you give it a look!

I actually covered the first part of this tutorial during a livestream, so here’s a quick summary of what the tutorial will teach you!

#01 – Writing Your First Feature

A Feature is the basic building block of TCA, its goal is to encapsulate state and business logic.

The idea behind a Feature is both simple and elegant:

  • a Feature exposes its current State

  • it also exposes a list of Action it can receive

  • finally, it implements a Reducer, which updates the current State when an Action is received

#02 – Adding Side Effects

Of course, seeing the example above, you might be thinking that this is too simple to implement a real world iOS app.

For instance, how can a network call, or any other asynchronous operation, fit within this simple model?

That’s when Effect comes into play!

Effect is TCA’s way of implementing a side effect.

Once again, the way it works is quite elegant:

  • after a Reducer has processed an Action, it can emit an Effect

  • and when that Effect completes, it can in turn emit another Action

  • …which will contain the result of the Effect and will be processed to update the State accordingly ✌️

#03 – Testing Your Feature

As you can see, writing an app using TCA requires a bit of additional code in order to make everything fit within the architecture.

But this extra code has not been written in vain, because one of the great features of TCA is that the code you write is pretty easy to test!

Because our State and Action have been nicely encapsulated, writing a test becomes as simple as sending an Action and then describing the expected changes to the State:

And even side effects are fairly easy to test:

  • we can inject mocked version of our dependencies

  • and we can assert that an Effect has indeed sent an Action 👌


As we’ve seen, TCA is a pretty interesting approach to writing iOS apps!

And even if you don’t plan to adopt this architecture, I would still recommend that you follow its tutorial: TCA makes use of a lot of very smart ideas, and knowing them can only make you a better engineer 😌


That’s all for this email, thanks for reading it!

If you’ve enjoyed it, feel free to forward it
to your friends and colleagues 🙌

I wish you an amazing week!

❤️

Previous
Previous

Bad practice: using "YYYY" to format a Date

Next
Next

Did you know that Xcode has a search history? 💡