title: Show SVProgressHUD on viewWillDisappear
body: <p>Context : My <code>UIViewController</code> is showing an edit profile view, with a few <code>UITextField</code> (first name, last name, birthday, ...). There is no &quot;save button&quot;, the values update on the database as soon as the <code>textFieldDidEndEditing</code> is called.</p>
  <p>I want to show a loading view (I'm using SVProgressHUD library) if the user try to leave the <code>UIViewController</code> before all database updates are finished.</p>
  <p>So here is my code (if updateWaitingConfirm is empty that means all updates are done) :</p>
  <pre><code>override func viewWillDisappear(_ animated: Bool) {
      
      if !updateWaitingConfirm.isEmpty {
          
          self.showSVProgressHUD(message: NSLocalizedString(&quot;updateWaiting&quot;, comment: &quot;&quot;))
          
          timeToWaitCount = 0
          let group = DispatchGroup()
          group.enter()
          
          checkWaitingConfirmEmpty(group)
          
          group.wait()
          self.dismissSVProgressHUD()
      }
      
      super.viewWillDisappear(animated)
  }
  
  func checkWaitingConfirmEmpty(_ group: DispatchGroup) {
      
      DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + 0.5) {
          self.timeToWaitCount += 0.5
          if self.updateWaitingConfirm.isEmpty || self.timeToWaitCount &gt; self.maxTimeToWaitForUpdates {
              group.leave()
          } else {
              self.checkWaitingConfirmEmpty(group)
          }
      }
  }
  </code></pre>
  <p>When all updates are done (or when it's been more than maxTimeToWaitForUpdates (10 seconds)), the <code>group.leave()</code> is called and then I call my function to dismissHUD and call the <code>super.viewWillDisappear()</code></p>
  <p>The problem is that nothing appears on my view, I also tried to edit a textfield for example and it doesn't work either.
  I also tried to call <code>view.layoutIfNeeded()</code> after the showSVProgressHUD but it's not working.</p>
  <p>Good to know : I can't just call a method on my back button <code>touchUpInside</code> method because the user can also quit the <code>UIViewController</code> with <code>interactivePopGestureRecognizer</code>.</p>
  <p>Thanks!</p>