Challenge - 5 Problems
Pull-to-Refresh Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when you pull down on a SwiftUI List with .refreshable modifier?
Consider a SwiftUI List with the .refreshable modifier added. What is the expected behavior when the user pulls down on the list?
iOS Swift
List(items, id: \.self) { item in
Text(item)
}
.refreshable {
await fetchData()
}Attempts:
2 left
💡 Hint
Think about what .refreshable is designed to do in SwiftUI.
✗ Incorrect
The .refreshable modifier adds pull-to-refresh support to scrollable views like List. When the user pulls down, the async closure runs and a spinner shows until it finishes.
❓ lifecycle
intermediate1:30remaining
When does the refresh closure run in a SwiftUI .refreshable modifier?
In SwiftUI, the .refreshable modifier takes an async closure. When exactly is this closure executed?
iOS Swift
List { ... }
.refreshable {
await loadData()
}Attempts:
2 left
💡 Hint
Think about user interaction with pull-to-refresh.
✗ Incorrect
The refresh closure runs only when the user pulls down the list far enough to activate the refresh control.
🔧 Debug
advanced2:30remaining
Why does the spinner never stop after pull-to-refresh in this SwiftUI code?
Given this SwiftUI code snippet, the spinner shows but never disappears after pulling to refresh. What is the cause?
iOS Swift
List(items, id: \.self) { item in
Text(item)
}
.refreshable {
fetchData()
}Attempts:
2 left
💡 Hint
Check if the async function is awaited properly.
✗ Incorrect
The .refreshable closure expects an async function to be awaited. If fetchData() is not awaited, SwiftUI never knows when refresh ends, so spinner stays.
🧠 Conceptual
advanced1:00remaining
What is the minimum iOS version that supports SwiftUI's .refreshable modifier?
You want to use the .refreshable modifier in your SwiftUI app. Which iOS version must your app target at minimum?
Attempts:
2 left
💡 Hint
Check Apple documentation for .refreshable availability.
✗ Incorrect
The .refreshable modifier was introduced in iOS 15.0, so apps must target at least iOS 15 to use it.
expert
3:00remaining
How to programmatically trigger pull-to-refresh in SwiftUI List with .refreshable?
You want to start the refresh spinner and call the refresh closure programmatically without user pulling down. Which approach works best?
Attempts:
2 left
💡 Hint
SwiftUI does not provide a direct API to trigger .refreshable programmatically.
✗ Incorrect
SwiftUI's .refreshable modifier does not expose a way to start refresh programmatically. Using UIKit's UIRefreshControl bridged via UIViewRepresentable is the common workaround.