A. The list reloads with new items after fetchNewItems completes
B. The list scrolls to the top without changing data
C. Nothing happens because refreshable requires a button
D. The app crashes due to missing completion handler
Solution
Step 1: Understand the effect of .refreshable with async closure
When user pulls down, fetchNewItems() runs asynchronously to update data.
Step 2: Identify expected behavior after data fetch
After fetchNewItems() completes, the list reloads showing updated items.
Final Answer:
The list reloads with new items after fetchNewItems completes -> Option A
Quick Check:
Pull-to-refresh triggers async update = list reload [OK]
Hint: Pull triggers async fetch, then list updates [OK]
Common Mistakes:
Thinking refreshable needs a button
Assuming no data change happens
Believing app crashes without completion
4. What is wrong with this SwiftUI pull-to-refresh code?
List(data) { item in
Text(item.name)
}
.refreshable {
fetchData()
}
medium
A. List requires an explicit id parameter
B. refreshable cannot be used on List
C. fetchData() is missing await and async keywords
D. Text cannot display item.name
Solution
Step 1: Check the refreshable closure requirements
The closure must be async and await the async function inside.
Step 2: Identify missing async/await usage
fetchData() is called without await and the closure is not marked async, causing a compile error.
Final Answer:
fetchData() is missing await and async keywords -> Option C
Quick Check:
refreshable closure must be async with await calls [OK]
Hint: Use async closure and await inside refreshable [OK]
Common Mistakes:
Forgetting to mark closure async
Calling async functions without await
Thinking refreshable can't be used on List
5. You want to add pull-to-refresh to a SwiftUI ScrollView that shows a list of messages. Which approach correctly updates the messages asynchronously when pulled?
hard
A. Use .onPull modifier with a synchronous closure
B. Use .refreshable on ScrollView with an async closure that updates the messages array
C. Add a Button inside ScrollView to manually refresh messages
D. Wrap ScrollView in a VStack and call a refresh function onAppear
Solution
Step 1: Identify the correct modifier for pull-to-refresh on ScrollView
The .refreshable modifier works on ScrollView and accepts an async closure.
Step 2: Confirm asynchronous update of messages
The async closure should update the messages array to refresh the UI after pull.
Step 3: Evaluate other options
The other options do not provide pull-to-refresh behavior: using non-existent modifiers, refreshing on appear, or requiring manual buttons.
Final Answer:
Use .refreshable on ScrollView with an async closure that updates the messages array -> Option B
Quick Check:
Pull-to-refresh on ScrollView = .refreshable async closure [OK]
Hint: Use .refreshable with async closure on ScrollView [OK]
Common Mistakes:
Trying to refresh with onAppear instead of pull
Using buttons instead of pull-to-refresh
Using non-existent modifiers like .onPull
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.