title: Does NSURLSession for HTTP data task (NSURLSessionDataTask) runs in background thread or we will have to provide the queue?
body: <p>I started to use <code>NSURLSession</code> by avoiding <code>NSURLConnection</code> now a days as it's a new and elegant API provided by Apple. Previously, I used to put call <code>NSURLRequest</code> in <code>GCD</code> block to execute it in background. Here is how I used to do in past:</p>
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  
      NSURL *url = [NSURL URLWithString:@&quot;www.stackoverflow.com&quot;];
      NSURLRequest *request = [NSURLRequest requestWithURL:url];
      NSURLResponse *response;
      NSError *error;
      NSData *data = [NSURLConnection sendSynchronousRequest:request 
                                           returningResponse:&amp;response 
                                                       error:&amp;error];
      if (error) {
          // Handle error
          return;
      }
      dispatch_async(dispatch_get_main_queue(), ^{
          // Do something with the data
      });
  });
  </code></pre>
  <p>Now, here is how I use <code>NSURLSession</code>:</p>
  <pre><code>- (void)viewDidLoad 
  {
      [super viewDidLoad];
   
      /*-----------------*
          NSURLSession
       *-----------------*/
  
      NSURL *url = [NSURL URLWithString:@&quot;https://itunes.apple.com/search?term=apple&amp;media=software&quot;];
  
      NSURLSession *session = [NSURLSession sharedSession];
      NSURLSessionDataTask *dataTask = [session dataTaskWithURL:url
                                              completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) 
      {
          NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data 
                                                               options:0
                                                                 error:nil];
          NSLog(@&quot;%@&quot;, json);
      }];
  }
  </code></pre>
  <p>I want to know that, will my request be executed on background thread itself or I will have to provide my own mechanism same way I did in case of <code>NSURLRequest</code> ?</p>