title: segue called twice when using DispatchQueue.main.async
body: <p>I'm trying to perform a segue to a new view controller, but the segue is being called twice and the new view controller appears twice.<br>I'm using a method that performs a GET request to an API to retrieve data.<br>That method uses a completion handler. </p>
  
  <pre><code>func getSearchResultsForQuery(_ query: String, completionHandlerForSearchResultsForQuery: @escaping (_ success: Bool, _ error: NSError?) -&gt; Void)
  </code></pre>
  
  <p>When the method completes successfully my segue is called, from within the main queue as is required. </p>
  
  <p>I've set breakpoints so I could see what was going on and the execution jumps from the performSegue back up to the conditional that checks if the method was successful and then continues until the segue is called a second time. <br>I've tried a purely programatic segue, but the result was the same.<br>I also added a print statement, and if I comment out the segue the print statement is only called once.</p>
  
  <p>I've used this same pattern a number of times before and never had a problem with it and I just can't figure out why this is happening.<br>The only thing I'm doing different this time is using Swift 3 and using DispatchQueue.main.async instead of dispatch_async(dispatch_get_main_queue(). <br><br>Here is the function which is giving me this problem:</p>
  
  <pre><code>    @IBAction func search(_ sender: UIButton) {
  
          let searchQuery = searchField.text
  
          TIClient.sharedInstance().getSearchResultsForQuery(searchQuery!) { (success, error) in
  
              if success {
                  print("Food items fetch successful")
                  DispatchQueue.main.async {
                      print("Perorming segue for food item: \(searchQuery)")
                      self.performSegue(withIdentifier: "showFoodItems", sender: self)
                  }
              } else {
                  print("error: \(error)")
              }
          }
  }
  </code></pre>
  
  <p>Edit: I never found out what the problem was, but completely deleting the story board and recreating it solved it.</p>