title: How to return data from background thread ?
body: <p>I have a method that should return an array which is populated in a background thread. I would like to wait with the return statement until the array is completely populated. How would I do that ? I know how to process data with no return type, but I would like to call this function and get the populated array. </p>
  
  <p>Example (Here the array ends up empty because it returns before array is populated - I would like to do something to return the populated array) : </p>
  
  <pre><code>-(NSArray*)fetchSomeArray{
  
      __block NSArray *arrayToReturn;
  
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,(unsigned long)NULL), ^(void) {
  
          NSArray *someArray = ...; // getting some array from database
          arrayToReturn = [NSMutableArray new];
  
          for(int i=0;i&lt;someArray.count;i++){
  
              [arrayToReturn addObject:...];
          }
  
      });
  
      return arrayToReturn;
  
  }
  </code></pre>