How do I implement pull-to-refresh in SwiftUI with Swift?

SwiftUI, pull to refresh, Swift, iOS Development
This example demonstrates how to implement pull-to-refresh functionality in a SwiftUI application.
import SwiftUI struct ContentView: View { @State private var items = ["Item 1", "Item 2", "Item 3"] @State private var isFetching = false var body: some View { NavigationView { List { ForEach(items, id: \.self) { item in Text(item) } } .navigationTitle("Pull to Refresh") .refreshable { await fetchData() } } } func fetchData() async { isFetching = true try? await Task.sleep(nanoseconds: 2_000_000_000) items.append("Item \(items.count + 1)") isFetching = false } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }

SwiftUI pull to refresh Swift iOS Development