title: How to call a method every x seconds in Objective-C using NSTimer?
body: <p>I am using Objective-C, Xcode 4.5.1 and working on an app for the iPhone.</p>
  
  <p>I have a method A in which I want to call another method B to do a series of calculations every x seconds. In method A I start playing an audio file. Method B will monitor the audio every x seconds for the duration of the audio file.</p>
  
  <p>I have found <code>NSTimer</code> as a potential solution, but am having a hard time getting it to work/understanding it.</p>
  
  <p>I simply want to call Method B every x seconds and run its calculations, but <code>NSTimer</code> requires me to provide several things of which I'm not sure what I'm supposed to tell it.</p>
  
  <pre><code>[NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval) 
  target:(id) select:(SEL) userInfo:(id) repeats:(BOOL)];
  </code></pre>
  
  <p>It is my understanding that at <code>NSTimeInterval</code> I provide the interval at which I want <code>NSTimer</code> to operate. But, how do I tell it to run Method B? </p>
  
  <p>I have looked at example code, and am currently under the impression that I provide the method at the '<code>select:</code>'. But, what do I write at the '<code>target:</code>'? Why would I need a target? I tried entering '<code>self</code>', but Xcode tells me: </p>
  
  <blockquote>
    <p>Use of undeclared identifier 'self'</p>
  </blockquote>
  
  <pre><code>[NSTimer scheduledTimerWithTimeInterval:0.1 target:self 
  select:@selector(targetMethod:myVolumeMonitor()) userInfo:nil repeats:YES];
  </code></pre>
  
  <p>So, I figure '<code>self</code>' is supposed to be a pointer to an object, but where do I want to point to?</p>
  
  <p>Below is a simplification of my code:</p>
  
  <pre><code>MethodA()
  {
  //Start playing an audio file.
  
  //NSTimer calling Method B, as long the audio file is playing, every x seconds.
  }
  
  MethodB()
  {
  //Do calculations.
  }
  </code></pre>
  
  <p>I would be grateful if somebody could provide me with some answers/point me in the right direction! (:</p>