title: SwiftUI: Forcing an Update
body: <p>Normally, we're restricted from discussing Apple prerelease stuff, but I've already seen plenty of SwiftUI discussions, so I suspect that it's OK; just this once.</p>
  
  <p>I am in the process of driving into the weeds on one of the tutorials (I do that).</p>
  
  <p>I am adding a pair of buttons below the swipeable screens in the "Interfacing With UIKit" tutorial: <a href="https://developer.apple.com/tutorials/swiftui/interfacing-with-uikit" rel="noreferrer">https://developer.apple.com/tutorials/swiftui/interfacing-with-uikit</a></p>
  
  <p>These are "Next" and "Prev" buttons. When at one end or the other, the corresponding button hides. I have that working fine.</p>
  
  <p>The problem that I'm having, is accessing the UIPageViewController instance represented by the PageViewController.</p>
  
  <p>I have the currentPage property changing (by making the PageViewController a delegate of the UIPageViewController), but I need to force the UIPageViewController to change programmatically.</p>
  
  <p>I know that I can "brute force" the display by redrawing the PageView body, reflecting a new currentPage, but I'm not exactly sure how to do that.</p>
  
  <pre><code>struct PageView&lt;Page: View&gt;: View {
      var viewControllers: [UIHostingController&lt;Page&gt;]
      @State var currentPage = 0
  
      init(_ views: [Page]) {
          self.viewControllers = views.map { UIHostingController(rootView: $0) }
      }
  
      var body: some View {
          VStack {
              PageViewController(controllers: viewControllers, currentPage: $currentPage)
  
              HStack(alignment: .center) {
                  Spacer()
  
                  if 0 &lt; currentPage {
                      Button(action: {
                          self.prevPage()
                      }) {
                          Text("Prev")
                      }
  
                      Spacer()
                  }
  
                  Text(verbatim: "Page \(currentPage)")
  
                  if currentPage &lt; viewControllers.count - 1 {
                      Spacer()
  
                      Button(action: {
                          self.nextPage()
                      }) {
                          Text("Next")
                      }
                  }
  
                  Spacer()
              }
          }
      }
  
      func nextPage() {
          if currentPage &lt; viewControllers.count - 1 {
              currentPage += 1
          }
      }
  
      func prevPage() {
          if 0 &lt; currentPage {
              currentPage -= 1
          }
      }
  }
  </code></pre>
  
  <p>I know the answer should be obvious, but I'm having difficulty figuring out how to programmatically refresh the VStack or body.</p>