title: Update UI in UIAlertAction handler
body: <p>Could you try to help me to solve the problem of updating the UI of my program while showing the UIAlertView instance?
  That's the situation:</p>
  
  <ol>
  <li>I'm pressing the toolbar "hide-button" and the alertView is opening;</li>
  <li>In the handler of UIAlertAction (OK button) i have a code, where i make several operations:
  
  <ul>
  <li>remove the toolbar "hide-button" pressed and set the button item with activity indicator instead;</li>
  <li>making the indicator rolling;</li>
  <li>THEN AND ONLY AFTER PREVIOUS STEPS next part of code should start and the data model is being updated, and because it's connected to the tableView by means of NSFetchedResultsControllerDelegate, the tableView's data is gonna be updated automatically. This step can take some time, so it's extremely needed to hold it asynchronously, and while it's being processed the activity indicator should roll;</li>
  <li>after that the activity indicator rolling faults, the toolbar button item with it is being removed and the "hide-button" (removed at the 1st step) comes back.
  FINISH.</li>
  </ul></li>
  </ol>
  
  <p>The problem's with updating the UI, when i exchange "hide-button" and "activity-button". </p>
  
  <pre><code>private var hideDataBarButtonItem: UIBarButtonItem?
  private var indicatorBarButtonItem = UIBarButtonItem(customView: UIActivityIndicatorView(activityIndicatorStyle: .Gray))
  
  override func viewDidLoad() {
      super.viewDidLoad()
      ...
      hideDataBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Stop, target: self, action: #selector(hideAllLoginData))
      toolbarItems?.insert(hideDataBarButtonItem!, atIndex: 2)
  }
  </code></pre>
  
  <p>That's the action for hideDataBarButtonItem:</p>
  
  <pre><code>@IBAction func hideAllLoginData(sender: AnyObject) {
      let confirmAlert = UIAlertController(title: "Hide all data?", message: "", preferredStyle: .Alert)
  
      confirmAlert.addAction( UIAlertAction(title: "OK", style: .Default, handler: { action in
          // remove the clear-button, set the indicator button instead and start indicator rolling
          self.toolbarItems?.removeAtIndex(2)
          self.toolbarItems?.insert(self.indicatorBarButtonItem, atIndex: 2)
          (self.indicatorBarButtonItem.customView as! UIActivityIndicatorView).startAnimating()
          print("button with indicator added")
  
          sleep(5) // -&gt; CHECK: this moment indicator should be visible and rolling!
  
          dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)) {
              for section in self.resources {
                  for resource in section {
                      if resource.defRecord != nil {
                          resource.defRecord = nil
                      }
                  }
              }
              print("data cleared")
  
              dispatch_async(dispatch_get_main_queue()) {
                  // remove indicator and set the clear-button back
                  print("button with indicator removed")
                  (self.indicatorBarButtonItem.customView as! UIActivityIndicatorView).stopAnimating()
                  self.toolbarItems?.removeAtIndex(2)
                  self.toolbarItems?.insert(self.hideDataBarButtonItem!, atIndex: 2)
              }
          }
      }) )
      confirmAlert.addAction( UIAlertAction(title: "Cancel", style: .Cancel, handler: nil ) )
  
      self.presentViewController(confirmAlert, animated: true, completion: nil)
  }
  </code></pre>
  
  <p>The result of the execution:</p>
  
  <pre><code>button with indicator added
  // -&gt; 5 sec of awaiting, but that's nothing in interface changed!
  data cleared
  button with indicator removed
  </code></pre>
  
  <p>If i don't remove the indicator button, i can see it after all, but it has to appear earlier. What do i make wrong?
  Thank you!</p>