Bird
0
0

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📝 ui behavior Q15 of 15
iOS Swift - Lists and Data Display
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?
AUse <code>.onPull</code> modifier with a synchronous closure
BUse <code>.refreshable</code> on ScrollView with an async closure that updates the messages array
CAdd a Button inside ScrollView to manually refresh messages
DWrap ScrollView in a VStack and call a refresh function onAppear
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct modifier for pull-to-refresh on ScrollView

    The .refreshable modifier works on ScrollView and accepts an async closure.
  2. Step 2: Confirm asynchronous update of messages

    The async closure should update the messages array to refresh the UI after pull.
  3. 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.
  4. Final Answer:

    Use .refreshable on ScrollView with an async closure that updates the messages array -> Option B
  5. Quick Check:

    Pull-to-refresh on ScrollView = .refreshable async closure [OK]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes