title: Run http request on other thread on ios
body: <p>so I want my app not to lock the GUI while sending an http request and getting the response, I made an attempt, but it complains that i use uikit outside of the mainthread, can someone please tell me the proper way of separating the http and the gui?</p>
  
  <pre><code>-(void)parseCode:(NSString*)title{
  
      UIActivityIndicatorView *spinner;
      spinner.center = theDelegate.window.center;
      spinner.tag = 12;
      [theDelegate.window addSubview:spinner];
      [spinner startAnimating];
  
      dispatch_queue_t netQueue = dispatch_queue_create("com.david.netqueue", 0);
  
      dispatch_async(netQueue, ^{
          NSString *url =[NSString stringWithFormat:@"http://myWebService.org/"];
          // Setup request
          NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
          [request setURL:[NSURL URLWithString:url]];
          [request setHTTPMethod:@"POST"];
          NSString *contentType = [NSString stringWithFormat:@"application/x-www-form-urlencoded"];
          [request addValue:contentType forHTTPHeaderField:@"Content-Type"];
  
          NSMutableString *data = [[NSMutableString alloc] init];
          [data appendFormat:@"lang=%@", @"English"];
          [data appendFormat:@"&amp;code=%@", theDelegate.myView.text ];
          [data appendFormat:@"&amp;private=True" ];
          [request setHTTPBody:[data  dataUsingEncoding:NSUTF8StringEncoding]];
          NSHTTPURLResponse *urlResponse = nil;
          NSError *error = [[NSError alloc] init];
  
          NSData *responseData = [NSURLConnection sendSynchronousRequest:request
                                               returningResponse:&amp;urlResponse
                                                           error:&amp;error];
  
          NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  
  
          dispatch_async(dispatch_get_main_queue(), ^{
  
              [spinner stopAnimating];
              [spinner removeFromSuperview];
              [self presentResults:result];
          });
  
      });
  
  }
  </code></pre>