Member-only story
How to Convert Your iOS Network Layer to Work With Combine or Async/await
Adapting your network layer to different interfaces
This year, Swift introduced the new async
and await
keyword. With them, we now have three ways to perform network operations:
- By using the old callbacks model
- By using
Combine
- By using
async-await
In some cases, we make a decision early on one technology and we try to use it in all the modules of our app: if we start with Combine
, for example, we may want to use Combine
everywhere.
This approach has the clear upside of consistency: we don’t have to think about how to implement something and people joining the project won’t be surprised with multiple technologies when exploring the codebase.
The cost of consistency is flexibility. We would like to use the best tool for each situation. We could have modules that require us to use Combine
for streams of events and others that could work with a callback for one-shot operations.
In today’s article, we explore how to convert a network layer from one technology to another. The network layer is just an example: whenever you need to transform an API from a technology to another, we can tap into these techniques.