title: SwiftUI pagination for List object
body: <p>I've implemented a List with a search bar in SwiftUI. Now I want to implement paging for this list. When the user scrolls to the bottom of the list, new elements should be loaded. My problem is, how can I detect that the user scrolled to the end? When this happens I want to load new elements, append them and show them to the user.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>import Foundation
  import SwiftUI
  
  struct MyList: View {
      @EnvironmentObject var webService: GetRequestsWebService
  
      @ObservedObject var viewModelMyList: MyListViewModel
  
      @State private var query = ""
  
      var body: some View {
  
          let binding = Binding&lt;String&gt;(
              get: { self.query },
              set: { self.query = $0; self.textFieldChanged($0) }
          )
  
          return NavigationView {
              // how to detect here when end of the list is reached by scrolling?
              List {
                  // searchbar here inside the list element
                  TextField("Search...", text: binding) {
                      self.fetchResults()
                  }
  
                  ForEach(viewModelMyList.items, id: \.id) { item in
                      MyRow(itemToProcess: item)
                  }
              } 
              .navigationBarTitle("Title")
          }.onAppear(perform: fetchResults)
  
      }
  
      private func textFieldChanged(_ text: String) {        
          text.isEmpty ? viewModelMyList.fetchResultsThrottelt(for: nil) : viewModelMyList.fetchResultsThrottelt(for: text)
      }
  
      private func fetchResults() {
          query.isEmpty ? viewModelMyList.fetchResults(for: nil) : viewModelMyList.fetchResults(for: query)
      }
  }
  </code></pre>
  
  <p>Also a little bit special this case, because the list contains the search bar. I would be thankful for any advice because with this :).</p>