Pull-to-Refresh
Reload data with the refreshable modifier.
Pull-to-Refresh is a free SwiftUI Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Refreshing on Demand
Users expect to pull a list down to reload it. SwiftUI bakes this gesture in with a single modifier, no gesture code required. ✨
Meet refreshable
Attach the refreshable modifier to a List. Pulling down reveals a spinner and runs the async work you provide.
.refreshable {
await reload()
}It Expects Async Work
The refreshable closure is async, so it pairs perfectly with await and modern Swift concurrency for fetching data.
Spinner Tied to Your Task
The pull-to-refresh spinner stays visible until your await finishes. SwiftUI hides it the moment the work completes.
A Simple Reload
Inside refreshable, call an async function that fetches fresh data and updates your @State array on completion.
func reload() async {
items = await fetchItems()
}Awaiting a Network Call
A real reload usually awaits a network request. Use URLSession with async/await to pull new items from a server.
let (data, _) = try await
URLSession.shared.data(from: url)Update State After Await
Once the await returns, assign the decoded results to your @State array and the list refreshes with the new rows.
let fresh = try decoder.decode(
[Item].self, from: data)
items = freshHandle Errors Gracefully
Network calls can fail. Wrap the work in do/catch so a dropped connection shows a message instead of crashing.
do {
items = try await fetchItems()
} catch {
showError = true
}Refreshable Needs a List
The pull gesture only works on scrollable containers like List or ScrollView. Attaching refreshable to a VStack does nothing.
Keep It Quick
Refresh should feel snappy. If your fetch is slow, show progress and avoid blocking the main thread with heavy work.
Pairs With Other Editing
Pull-to-refresh sits happily beside onDelete, onMove, and add. Together they make a fully interactive, editable list. ✨
Quick Check
What kind of closure does refreshable take?
Recap: Pull-to-Refresh
You added reload-on-pull with the async refreshable modifier on a List, awaiting fresh data and handling errors. 🎉
Frequently asked questions
Is the “Pull-to-Refresh” lesson free?
Yes — the full text of “Pull-to-Refresh” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.
What will I learn in “Pull-to-Refresh”?
Reload data with the refreshable modifier. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start SwiftUI Academy?
No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Pull-to-Refresh” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this SwiftUI Academy lesson?
Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Swipe-to-Delete Rows
- Reordering with onMove
- Adding New Items
- Pull-to-Refresh