0
0
iOS Swiftmobile~5 mins

Await keyword in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the await keyword do in Swift?
The await keyword pauses the current function until an asynchronous task finishes, allowing other code to run meanwhile.
Click to reveal answer
beginner
Can you use await outside an asynchronous function in Swift?
No, await can only be used inside functions marked with async.
Click to reveal answer
intermediate
How does await improve app responsiveness?
await lets the app do other work while waiting for slow tasks, like network calls, so the app stays smooth and doesn’t freeze.
Click to reveal answer
intermediate
What happens if you forget to use await when calling an async function?
The async function returns a task immediately without waiting for the result, which can cause bugs if you expect the result right away.
Click to reveal answer
beginner
Example: What does this code do?
<pre>func fetchData() async {
  let data = await download()
  print(data)
}</pre>
This function waits for download() to finish before printing the data. The await pauses fetchData() until download() completes.
Click to reveal answer
Where can you use the await keyword in Swift?
AOnly inside functions marked with <code>async</code>
BInside any function
COnly in the main thread
DOnly in classes
What does await do when calling an async function?
APauses execution until the async function finishes
BIgnores the function result
CRuns the function synchronously
DRuns the function twice
What happens if you call an async function without await?
AYou get a compile error
BYou get a task object immediately without waiting
CThe function runs synchronously
DThe app crashes
Why is using await good for app performance?
AIt blocks the main thread
BIt makes code run faster synchronously
CIt lets other code run while waiting
DIt disables multitasking
Which keyword must a function have to use await inside it?
Adefer
Bsync
Cawait
Dasync
Explain in your own words how the await keyword works in Swift and why it is useful.
Think about how waiting for slow tasks can freeze an app and how <code>await</code> helps avoid that.
You got /4 concepts.
    Describe a simple example where you would use await in a Swift app.
    Imagine fetching data from the internet and needing to wait for it before showing it.
    You got /4 concepts.