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

In SwiftUI, adding a pull-to-refresh feature to a list is quite straightforward. You can achieve this by utilizing the `refreshable` modifier available in iOS 15 and later. This allows you to refresh the list content by pulling down on the list. Below is a simple example of how to implement this feature.

SwiftUI, Pull-to-Refresh, iOS, Swift
A comprehensive guide on implementing the pull-to-refresh feature in SwiftUI lists using Swift programming language.
struct ContentView: View { @State private var items = ["Item 1", "Item 2", "Item 3"] var body: some View { List(items, id: \.self) { item in Text(item) } .refreshable { // Simulate network loading await Task.sleep(2 * 1_000_000_000) // 2 seconds items.append("New Item \(items.count + 1)") } .navigationTitle("Pull to Refresh") } }

SwiftUI Pull-to-Refresh iOS Swift