title: Updating the UI using "dispatch_async(dispatch_get_main_queue(),^{block})
body: <p>I wanted to update the UI in the NSURLSession's completion block. 
  The initial implementation didn't update the UI immediately. It updated the UI maybe 20 seconds later. Here is the initial implementation. </p>
  
  <pre><code>  NSURLSessionDataTask *task = [self.session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
          NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
  
          UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 150, 150)];
          label.backgroundColor = [UIColor greenColor];
          label.text = jsonDict[@"object_or_array"];
  
          dispatch_async(dispatch_get_main_queue(), ^{ 
              [self.view addSubview:label];
          });
      }];
  
      [task resume];
  </code></pre>
  
  <p>I moved the location of the <code>label.text = jsonDict[@"object_or_array"]</code> inside the main queue as following. </p>
  
  <pre><code> dispatch_async(dispatch_get_main_queue(), ^{ 
                  label.text = jsonDict[@"object_or_array"]
                  [self.view addSubview:label];
              });
  </code></pre>
  
  <p>Then the UI was updated immediately as expected. </p>
  
  <p>Could anyone tell me why this is?</p>