SwiftUI Refresh List ?!

Hi folks,

I am new to SwiftUI. I've got the following small code. All I want is to refresh the List after pull-to-refresh. Is there any "reloadData" ?

Thanks in advance!

Code Block language
import SwiftUI
import SwiftUIRefresh
struct ContentViewFavorite: View {
    
    let posts = Data.posts()
    @State private var isShowing = false
    var body: some View {
            List {
                ForEach(posts) { post in
                
                    PostViewFavorite(post: post)
                }.padding(.all, 20)
            }.pullToRefresh(isShowing: $isShowing) {
                     self.isShowing = false
            }
      
    }
}
struct ContentViewFavorite_Previews: PreviewProvider {
    static var previews: some View {
        ContentViewFavorite()
    }
}


First you need to refactor your data interface to use either @Binding, @Environment, @EnvironmentObject or @ObservedObject, because this line:
Code Block
let posts = Data.posts()

just statically instantiates your posts once.

In the block/closure that handles .pullToRefresh, which right now just toggles the state of isShowing, you invoke call the func to load further data. The response to this method needs to update the data model you referenced in the first step. The UI is then refreshed automatically.

Hope it helps

SwiftUI Refresh List ?!
 
 
Q