Async/await in Swift | What is it?!

Mammadowr
2 min readJul 23, 2022

--

If you did not check my following articles yet, then check them first and come back here! :)

Great that we met again after around 7 minutes! Let’s start with async/await. In this article, I am explaining to you what is async/await, how and why do we use it, and also at the end I will share with you some read-more articles from well experienced people.

We got the opportunity to use async/await right after WWDC21. Just a quick information for those who does not know what is WWDC. It is happening once a year and we hear about updates for Swift, Xcode and etc. So this is kind of update for us (I felt myself as an app now 😄).

With this, we got rid of unnecessary closure usage. We have an asynchronous structure that is more readable and executes operations properly.

If you follow me, you know that I love to keep everything as simple as it is possible and explain it to make clear for everyone:

async: Indicates that a method or function is asynchronous. Using this allows you to suspend execution until an async method returns a result.

await: Indicates that your code can pause execution while waiting for an asynchronously declared method or function to return.

I hear you, I hear that you are asking some code examples. Here we go:

Since WWDC21, instead of this:

We use this:

  • Read more:
  1. https://www.avanderlee.com/swift/async-await/
  2. https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html
  3. https://blog.mayflower.de/11079-async-await-swift.html

Basically that is all from my side. If you like my articles, if you think that they are useful, you can click on “Follow” button and share articles to reach more people. :)

--

--

Mammadowr

I speak 6 human and 5 programming languages. 🥳  iOS Developer. To support me: https://www.buymeacoffee.com/mammadowr8 ☕️