title: NSURLConnection Getting Off Main Thread
body: <p>Intro:
  I have basically learned Obj-C and Cocoa Touch from Stackoverflow over the last few weeks, so bravo community, bravo. </p>
  
  <p>Alas I have come to a question I cannot find an answer to/don't know how to Google.</p>
  
  <p>I am making an app that 100% interfaces with an API service. Here's the process:</p>
  
  <ol>
  <li>App launch -> Retrieve token</li>
  <li>Subsequent requests -> HTTP Header token</li>
  </ol>
  
  <p>My first view controller is a loading icon while a synchronous request takes place. </p>
  
  <p>I would like to make Async requests in the future as currently my UI gets blocked while these requests take place.</p>
  
  <p>My PHP background has caused me to set up my files like this, so let me know if this is incorrect.</p>
  
  <ul>
  <li>APIConnect.h/.m -> Holds all my API methods
  <code>-(NSDictionary *)APIcall:(NSString *)api postData:(NSDictionary *)postData</code></li>
  <li>TableViewController.h/.m -> Table based off data loaded from the method above.</li>
  </ul>
  
  <p>When selecting a row, it moves forward in the UI and retrieves the details of that item (another API call).</p>
  
  <p>When moving forward, it's apparent the main thread is blocked. </p>
  
  <p>I therefore have tried to set up an async method
  <code>-(NSDictionary *)asyncAPIcall:(NSString *)api postData:(NSDictionary *)postData</code></p>
  
  <p>APIConnect.m (abbreviated):</p>
  
  <pre><code>-(NSDictionary *)asyncAPIcall:(NSString *)api postData:(NSDictionary *)postData
  {
   [NSURLConnection sendAsynchronousRequest:request
                                     queue:queue
                         completionHandler:
   ^(NSURLResponse *response, NSData *data, NSError *error){
       if ([data length] &gt; 0 &amp;&amp; error == nil)
           [self returnedData:data];
       else
           [self downloadError:error];
  
   }];
  }
  
  
  -(void)returnedData:(NSData*)data
  {
      NSMutableDictionary *returnData = [[NSMutableDictionary alloc] init];
  
      [returnData setDictionary:[NSJSONSerialization JSONObjectWithData:data
                                                            options:0
                                                              error:nil]];
  
      NSLog(@"Returned Data %@", returnData);
      [self setReturnURLData:returnData];
  }
  </code></pre>
  
  <p>I really don't know how to ask my question, so maybe you can help me with that... However in theory I would like to:</p>
  
  <ul>
  <li>Make an async request within APIConnect.m</li>
  <li>Once async is done, it returns data to TableViewController.m</li>
  <li>Once TableViewController receives data it will run it's processing and run <code>[self.tableView reloadData];</code></li>
  <li>All meanwhile, an activity indicator or something is visible to show that it's working on getting something</li>
  </ul>
  
  <p>Any guidance on what to Google would be super helpful.</p>