title: How to reduce response time while data display , which is parsed by SOAP service
body: <ul>
  <li>I am trying to Parse SOAP data [using NSURLConnection, as I am not getting to use NSURLSession]</li>
  <li>and trying to display that on multiple UILabels</li>
  </ul>
  
  <p><strong>Issue is - when printing response data on Console it is printed quickly, but It is taking too much time (50-60 sec) to display on labels.</strong></p>
  
  <p>Please suggest me any possible way to display data quickly, Here is my code</p>
  
  <pre><code>#pragma mark - post data function
  -(void)getEmployeeData{
      //Renewed CODE
      loginData = [[NSMutableData alloc]init];
      NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
      NSString *methodName = @"Get_Data";
  
      //SOAP Start
      [connectionManagerObject getStartSoapData:loginData :methodName];
  
      //SOAP Body
      NSString *passedUserID = [[NSUserDefaults standardUserDefaults] objectForKey:@"StoredUserID"];
      //    NSLog(@"passed UserID : %@",passedUserID);
      NSString *passedPassword = [[NSUserDefaults standardUserDefaults] objectForKey:@"StoredPassword"];
      //    NSLog(@"passed Password : %@",passedPassword);
  
      NSString *userIdValue = [NSString stringWithFormat:@"&lt;EMP_NAME&gt;%@&lt;/EMP_NAME&gt;",passedUserID];
      NSString *passwordValue = [NSString stringWithFormat:@"&lt;EMP_PASSWORD&gt;%@&lt;/EMP_PASSWORD&gt;",passedPassword];
      [loginData appendData:[userIdValue dataUsingEncoding:NSUTF8StringEncoding]];
      [loginData appendData:[passwordValue dataUsingEncoding:NSUTF8StringEncoding]];
  
      //SOAP End
      [connectionManagerObject getEndSoapData:loginData :methodName];
  
      //SOAP Request
      [connectionManagerObject getRequest:loginData :request :[NSURL URLWithString:HOST_URL] :methodName];
  
      //Start connection
      [self startConnectionWithRequest:request];
  }
  
  #pragma mark - Start Connection
  -(void)startConnectionWithRequest:(NSMutableURLRequest *)URLRequest
  {
      loginConnection = [[NSURLConnection alloc]initWithRequest:URLRequest delegate:self startImmediately:YES];
  
      if (loginConnection)
      {
          //        NSLog(@" \n\n Successfully connected with server !!! ");
      }
      else
      {
          //        NSLog(@" \n\n Connection Not Established !!! ");
      }
  
      [loginConnection start];
  }
  
  #pragma mark - Connection Delegate
  
  -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  {
      [loginData setLength:0];
  }
  
  -(void)connection:(NSURLConnection *)connection didReceiveData:(nonnull NSData *)data
  {
      [loginData appendData:data];
  }
  
  -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
  {
      UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning !" message:@"Please Check your internet connection" preferredStyle:UIAlertControllerStyleAlert];
  
      UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
      [alertController addAction:ok];
      [self presentViewController:alertController animated:YES completion:nil];
  
  }
  
  -(void)connectionDidFinishLoading:(NSURLConnection *)connection
  {
  
      NSString *responseString = [[NSMutableString alloc]initWithData:loginData encoding:NSUTF8StringEncoding];
  
      responseString = [responseString substringFromIndex:[responseString rangeOfString:@"&lt;Get_DataResult&gt;"].location + [@"&lt;Get_DataResult&gt;" length]];
      responseString = [responseString substringToIndex:[responseString rangeOfString:@"&lt;/Get_DataResult&gt;"].location];
  
      //    NSLog(@"Response string : %@",responseString);
  
  
      if ([responseString containsString:@"^"])
      {
          [self displayProfileData:responseString];
      }
      else
      {
          UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning !" message:@"Please Check your login credentials" preferredStyle:UIAlertControllerStyleAlert];
  
          UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
          [alertController addAction:ok];
          [self presentViewController:alertController animated:YES completion:nil];
  
          [self.navigationController popViewControllerAnimated:NO];
  
      }
  
  
  }
  
  
  #pragma mark - Display data function
  
  -(void)displayProfileData:(NSString *)storedEmployeeResponse
  {
      [NSThread detachNewThreadSelector:@selector(start) toTarget:self withObject:nil];
  
      //GCD CODE
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
  
  
      // do my time consuming task and everytime it wants to update the UI,
      // it should dispatch that back to the main queue, e.g.
  
      NSArray *passEmpDataArray = [[NSArray alloc]init];
      passEmpDataArray = [storedEmployeeResponse componentsSeparatedByString:@"^"];
  
      NSString *empCodeStr = [passEmpDataArray objectAtIndex:0];
      NSString *empNameStr = [passEmpDataArray objectAtIndex:1];
      NSString *empDeptStr = [passEmpDataArray objectAtIndex:3];
      NSString *empDesgStr = [passEmpDataArray objectAtIndex:5];
      NSString *empGenderStr = [passEmpDataArray objectAtIndex:4];
      NSString *empDojStr = [passEmpDataArray objectAtIndex:6];
      NSString *empDobStr = [passEmpDataArray objectAtIndex:7];
      NSString *empEmailStr = [passEmpDataArray objectAtIndex:9];
      NSString *empMobileStr = [passEmpDataArray objectAtIndex:8];
  
  
  
      dispatch_sync(dispatch_get_main_queue(), ^{
  
      // update the UI accordingly
  
      _empCodeLabel.text = [NSString stringWithFormat:@"Emp Code    %@",empCodeStr];
      _empNameLabel.text = [NSString stringWithFormat:@"Emp Name   %@",empNameStr];
      _empDeptLabel.text = [NSString stringWithFormat:@"Emp Dept    %@",empDeptStr];
      _empDesgLabel.text = [NSString stringWithFormat:@"Emp Desg   %@",empDesgStr];
      _empGenderLabel.text = [NSString stringWithFormat:@"Gender         %@",empGenderStr];
      _empDojLabel.text = [NSString stringWithFormat:@"DOJ              %@",empDojStr];
      _empDobLabel.text = [NSString stringWithFormat:@"DOB              %@",empDobStr];
      _empEmailIdLabel.text = [NSString stringWithFormat:@"Email ID        %@",empEmailStr];
      _empMobileNo.text = [NSString stringWithFormat:@"Mobile No     %@",empMobileStr];
  
  
      NSString *tempUrl = [NSString stringWithFormat:Image_URL,empCodeStr];
      NSURL *url = [NSURL URLWithString:tempUrl];
      loginData = [NSMutableData dataWithContentsOfURL:url];
      _profilePic.image = [UIImage imageWithData:loginData];
  
      [self stop];
  
      });
  
      });
  
  }
  
  #pragma mark - post data function
  -(void)getEmployeeData
  {
  
      //Renewed CODE
      loginData = [[NSMutableData alloc]init];
      NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
      NSString *methodName = @"Get_Data";
  
      //SOAP Start
      [connectionManagerObject getStartSoapData:loginData :methodName];
  
      //SOAP Body
      NSString *passedUserID = [[NSUserDefaults standardUserDefaults] objectForKey:@"StoredUserID"];
      //    NSLog(@"passed UserID : %@",passedUserID);
      NSString *passedPassword = [[NSUserDefaults standardUserDefaults] objectForKey:@"StoredPassword"];
      //    NSLog(@"passed Password : %@",passedPassword);
  
      NSString *userIdValue = [NSString stringWithFormat:@"&lt;EMP_NAME&gt;%@&lt;/EMP_NAME&gt;",passedUserID];
      NSString *passwordValue = [NSString stringWithFormat:@"&lt;EMP_PASSWORD&gt;%@&lt;/EMP_PASSWORD&gt;",passedPassword];
      [loginData appendData:[userIdValue dataUsingEncoding:NSUTF8StringEncoding]];
      [loginData appendData:[passwordValue dataUsingEncoding:NSUTF8StringEncoding]];
  
      //SOAP End
      [connectionManagerObject getEndSoapData:loginData :methodName];
  
      //SOAP Request
      [connectionManagerObject getRequest:loginData :request :[NSURL URLWithString:HOST_URL] :methodName];
  
      //Start connection
      [self startConnectionWithRequest:request];
  }
  #pragma mark - Start Connection
  -(void)startConnectionWithRequest:(NSMutableURLRequest *)URLRequest
  {
      loginConnection = [[NSURLConnection alloc]initWithRequest:URLRequest delegate:self startImmediately:YES];
  
      if (loginConnection)
      {
          //        NSLog(@" \n\n Successfully connected with server !!! ");
      }
      else
      {
          //        NSLog(@" \n\n Connection Not Established !!! ");
      }
  
      [loginConnection start];
  }
  
  #pragma mark - Connection Delegate
  
  -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  {
      [loginData setLength:0];
  }
  
  -(void)connection:(NSURLConnection *)connection didReceiveData:(nonnull NSData *)data
  {
      [loginData appendData:data];
  }
  
  -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
  {
      UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning !" message:@"Please Check your internet connection" preferredStyle:UIAlertControllerStyleAlert];
  
      UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
      [alertController addAction:ok];
      [self presentViewController:alertController animated:YES completion:nil];
  
  }
  -(void)connectionDidFinishLoading:(NSURLConnection *)connection
  {
  
      NSString *responseString = [[NSMutableString alloc]initWithData:loginData encoding:NSUTF8StringEncoding];
  
      responseString = [responseString substringFromIndex:[responseString rangeOfString:@"&lt;Get_DataResult&gt;"].location + [@"&lt;Get_DataResult&gt;" length]];
      responseString = [responseString substringToIndex:[responseString rangeOfString:@"&lt;/Get_DataResult&gt;"].location];
  
      //    NSLog(@"Response string : %@",responseString);
  
  
      if ([responseString containsString:@"^"])
      {
          [self displayProfileData:responseString];
      }
      else
      {
          UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning !" message:@"Please Check your login credentials" preferredStyle:UIAlertControllerStyleAlert];
  
          UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
          [alertController addAction:ok];
          [self presentViewController:alertController animated:YES completion:nil];
  
          [self.navigationController popViewControllerAnimated:NO];
  
      }
  
  
  }
  
  
  #pragma mark - Display data function
  -(void)displayProfileData:(NSString *)storedEmployeeResponse
  {
      [NSThread detachNewThreadSelector:@selector(start) toTarget:self withObject:nil];
  
      //GCD CODE
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
  
  
      // do my time consuming task and everytime it wants to update the UI,
      // it should dispatch that back to the main queue, e.g.
  
      NSArray *passEmpDataArray = [[NSArray alloc]init];
      passEmpDataArray = [storedEmployeeResponse componentsSeparatedByString:@"^"];
  
      NSString *empCodeStr = [passEmpDataArray objectAtIndex:0];
      NSString *empNameStr = [passEmpDataArray objectAtIndex:1];
      NSString *empDeptStr = [passEmpDataArray objectAtIndex:3];
      NSString *empDesgStr = [passEmpDataArray objectAtIndex:5];
      NSString *empGenderStr = [passEmpDataArray objectAtIndex:4];
      NSString *empDojStr = [passEmpDataArray objectAtIndex:6];
      NSString *empDobStr = [passEmpDataArray objectAtIndex:7];
      NSString *empEmailStr = [passEmpDataArray objectAtIndex:9];
      NSString *empMobileStr = [passEmpDataArray objectAtIndex:8];
  
  
  
      dispatch_sync(dispatch_get_main_queue(), ^{
  
      // update the UI accordingly
  
      _empCodeLabel.text = [NSString stringWithFormat:@"Emp Code    %@",empCodeStr];
      _empNameLabel.text = [NSString stringWithFormat:@"Emp Name   %@",empNameStr];
      _empDeptLabel.text = [NSString stringWithFormat:@"Emp Dept    %@",empDeptStr];
      _empDesgLabel.text = [NSString stringWithFormat:@"Emp Desg   %@",empDesgStr];
      _empGenderLabel.text = [NSString stringWithFormat:@"Gender         %@",empGenderStr];
      _empDojLabel.text = [NSString stringWithFormat:@"DOJ              %@",empDojStr];
      _empDobLabel.text = [NSString stringWithFormat:@"DOB              %@",empDobStr];
      _empEmailIdLabel.text = [NSString stringWithFormat:@"Email ID        %@",empEmailStr];
      _empMobileNo.text = [NSString stringWithFormat:@"Mobile No     %@",empMobileStr];
  
  
      NSString *tempUrl = [NSString stringWithFormat:Image_URL,empCodeStr];
      NSURL *url = [NSURL URLWithString:tempUrl];
      loginData = [NSMutableData dataWithContentsOfURL:url];
      _profilePic.image = [UIImage imageWithData:loginData];
  
      [self stop];
  
      });
  
      });
  
  }
  </code></pre>