Bird
0
0

In Swift, what is the effect of declaring a function with the async keyword?

easy📝 Conceptual Q1 of 15
iOS Swift - Concurrency
In Swift, what is the effect of declaring a function with the async keyword?
AIt makes the function execute on the main thread only.
BIt allows the function to perform asynchronous operations and be awaited.
CIt forces the function to return immediately without any result.
DIt disables error handling inside the function.
Step-by-Step Solution
Solution:
  1. Step 1: Understand async keyword

    The async keyword marks a function as asynchronous, meaning it can perform work that might take time without blocking the thread.
  2. Step 2: Effect on function calls

    Such functions must be called with await to suspend execution until the async work completes.
  3. Final Answer:

    It allows the function to perform asynchronous operations and be awaited. -> Option B
  4. Quick Check:

    Async means function can be awaited [OK]
Quick Trick: Async marks functions for awaiting [OK]
Common Mistakes:
  • Thinking async forces main thread execution
  • Assuming async disables error handling
  • Believing async functions return immediately without result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes