SwiftUI 引入了 refreshablel() 修饰符。在本教程中,将从 Internet 获取一个 JSON 文件,并在启动拉动刷新时显示在列表中。
struct Contact: Decodable, Identifiable {
let id: Int
let name: String
let email: String
}
struct ContentView: View {
// 1.
@State private var contacts = [
Contact(id: 0, name: "SwiftUI", email: "Pull to refresh!")]
var body: some View {
NavigationView {
// 2.
List(contacts) { item in
VStack(alignment: .leading) {
Text(item.name)
.font(.title)
Text(item.email)
.font(.subheadli