プルして更新
refreshable モディファイアでデータを再読み込みします。
「プルして更新」はCoddyKit上の無料SwiftUI Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSwiftUI Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 SwiftUI Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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. 🎉
よくある質問
「プルして更新」レッスンは無料ですか?
はい。「プルして更新」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、SwiftUI Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 SwiftUI Academyコースには全4レッスンが含まれています。
「プルして更新」で何を学びますか?
refreshable モディファイアでデータを再読み込みします。 ブラウザで直接実行するハンズオンコードでSwiftUI Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
SwiftUI Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSwiftUI Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「プルして更新」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSwiftUI Academyレッスンでコードを書いて実行できますか?
はい。すべてのSwiftUI Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。