title: When should I apply Runloop to my program and why?
body: <p>My requirement is that I want to call an API to ask for some new information from my server every 6 seconds,so I wrote my code as below:</p>
  
  <pre><code>MyBackgroundThread(){
  
      while(self.isStop){
          [self callMyAPI]; 
          [NSThread sleepfortimeinterval : 6 ];
      }
  }
  </code></pre>
  
  <p>But I find out today that there is a way provided by Foundation library to write a run loop. So I can rewrite my code as below:</p>
  
  <pre><code>MyBackgroundThread(){
  
      NSTimer *timer = [NSTimer timerWithTimeInterval:6 target:self selector:@selector(callMyAPI) userInfo:nil repeats:YES];
      [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
      [timer release];
      while (! self.isCancelled) {
          BOOL ret = [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
      }
  }
  </code></pre>
  
  <p>However, I don't know if these is a better way to do my job then my original one? If it is, why? and how can I test the difference in efficiency(or other property?) between this two ways?</p>
  
  <p>Thanks!</p>