title: SwiftUI async Data fetch
body: <p>I am trying to learn SwiftUI and creating a movie search app with The movie Database API</p>
  
  <p>I would like to fetch new data once the scroll goes at the end of the List. I found a possible solution on SO using ForEach inside the List and checking when the list reaches the last item and then performing the onAppear() call.</p>
  
  <p><a href="https://stackoverflow.com/questions/56602089/in-swiftui-where-are-the-control-events-i-e-scrollviewdidscroll-to-detect-the">In SwiftUI, where are the control events, i.e. scrollViewDidScroll to detect the bottom of list data</a></p>
  
  <p>How can I load new pages from the search when the first page has loaded?</p>
  
  <p>You can find the project here, was too big to post
  <a href="https://github.com/aspnet82/MovieSearch" rel="nofollow noreferrer">https://github.com/aspnet82/MovieSearch</a></p>
  
  <p>SearchMovieManager -> Make the fetch call, I used Dispatch.main.async </p>
  
  <p>Here what the app should do</p>
  
  <ol>
  <li>Fetch the data from the API and display the first page -> WORKING</li>
  <li>When the List scroll to the last item makes another fetch request on the following page to load more data -> This not works, it works only for the second page of the request. It always displays the same data after the second fetch call.</li>
  </ol>
  
  <p>The issue I think is in the GCD, but I do not know how to queue things to make it works automatically</p>
  
  <p>UPDATE: A workaround I found:</p>
  
  <pre><code>List(searchMovieManager.allMovies) { movie in
       Text(movie.title)
  }
  Text("load more").onTapGesture {
       fetchNextPage(obs: self.searchMovieManager, page: self.searchMovieManager.pageTofetch)
   }
  </code></pre>
  
  <p>I think might be ok as solution, it adds new page once I tap on the button, and can be also fine in controlling data download maybe?</p>
  
  <p>Thanks for the help :)</p>