A. showData() must be marked async to use await inside it
B. Missing await keyword before getData()
C. getData() should not be async if awaited
D. print(message) cannot print async results
Solution
Step 1: Check where await is used
The await keyword is used inside showData(), but this function is not marked async.
Step 2: Understand async function rules
In Swift, you can only use await inside an async function or a Task closure. So showData() must be declared async.
Final Answer:
showData() must be marked async to use await inside it -> Option A
Quick Check:
Await requires async function = B [OK]
Hint: Use await only inside async functions or Task closures [OK]
Common Mistakes:
Forgetting to mark function async when using await
Thinking await can be used in normal functions
Confusing async function declaration with await usage
5. You want to fetch user data and then fetch user posts, both are async functions: fetchUser() and fetchPosts(userId:). How do you correctly wait for both results in sequence inside an async function?
hard
A. let user = await fetchUser()
let posts = await fetchPosts(userId: user.id)
B. let user = fetchUser()
let posts = fetchPosts(userId: user.id)
C. await let user = fetchUser()
await let posts = fetchPosts(userId: user.id)
D. let user = await fetchUser()
let posts = fetchPosts(userId: await user.id)
Solution
Step 1: Await the first async call to get user
You must use await before fetchUser() to get the user data before using it.
Step 2: Await the second async call using user.id
After getting the user, call fetchPosts(userId: user.id) with await to get posts.
Final Answer:
let user = await fetchUser()
let posts = await fetchPosts(userId: user.id) -> Option A
Quick Check:
Await each async call in order = C [OK]
Hint: Await each async call separately in sequence [OK]
Common Mistakes:
Not awaiting the second async call
Trying to await variable declarations incorrectly
Using await inside function arguments wrongly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.