title: perform background task on different thread in iOS
body: <p>How to preform certain operation in background on different thread, if it is executed on main thread it is blocking the UI of my app. any one have any idea how to do it?</p>
  
  <p>even if it prints NSLog in background it will be fine.
  i want to run following thing in no matter even if user presses HOME button.
  in my viewController i did this :</p>
  
  <pre><code>- (IBAction)btnStartClicked:(UIButton *)sender {
      [NSThread detachNewThreadSelector:@selector(StartBGTask) toTarget:self withObject:nil];
       }
  
  -(void)StartBGTask{
      [[[UIApplication sharedApplication] delegate] performSelector:@selector(startThread)];  
    }
  </code></pre>
  
  <p>and in appDelegate.m i have this method </p>
  
  <pre><code> -(void) startThread {
   @autoreleasepool {
      for (int i = 0; i &lt; 100; i++) {
          dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
              NSLog(@"current progress %d", i);
          });
          [NSThread sleepForTimeInterval:1];
      }
     }
   }
  </code></pre>
  
  <p>it prints integer from 1 to 100 on interval of 1 second.</p>