title: Multithreading in iOS - how to force a thread to wait for a condition?
body: <p>I'm creating an application that fetches a set of results from a database - I use <a href="https://github.com/jdg/MBProgressHUD" rel="noreferrer">MBProgressHUD</a> to show the progress of the query with an animation. The method I use calls the animation while executing a method in another thread and once it's done, it hides the animation. My question is, after calling:</p>
  
  <pre><code>[HUD showWhileExecuting:@selector(getResults) onTarget:self withObject:nil animated:YES];
  </code></pre>
  
  <p>I would like to, if there are no results, display an alert stating this, and if there are, load the next view. So far, I have this code:</p>
  
  <pre><code>[HUD showWhileExecuting:@selector(getResults) onTarget:self withObject:nil animated:YES];
  
  if(self.thereAreEvents) {
      [self performSegueWithIdentifier:@"searchResults" sender:self];
  } else {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No results" message:@"Sorry, there are no results for your search. Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
      [alert show];
      [alert release];
  }
  </code></pre>
  
  <p><code>self.thereAreEvents</code> gets set at the end of the <code>getResults</code> method. However, since that method gets called in another thread this line of execution continues and shows the alert, even though there are events in the database.</p>
  
  <p>So, from here, I have two questions: What is the easiest way to implement a wait-signal mechanism in iOS and what is the most efficient way to implement this sort of mechanism in iOS?</p>
  
  <p>Thanks!</p>