title: Getting results from a method called by NSTimer (obj-c)
body: <p>From what I can make out, NSTimer calls your method once despite how many times it repeats meaning you cannot get an updated result from a method?</p>
  
  <p>How would I implement the following using NSTimer? </p>
  
  <p>1) Loop forever using applescript to grab certain window titles</p>
  
  <pre><code>- (void) timer {
  if (!_timer){
  
      //Create timer , timer only gets called once and returns once?
      _timer = [NSTimer scheduledTimerWithTimeInterval: 1.0f
                                                 target: self
                                              selector: @selector(getWindowNames:)
                                               userInfo: nil repeats:YES];
  
      [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];
      [[NSRunLoop currentRunLoop] run];
      }
  }
  </code></pre>
  
  <p>2) Using applescript to grab the title windows</p>
  
  <pre><code>//Get the names of all running windows
  - (void) getWindowNames : (NSTimer*) timer{
  
  NSDictionary *error = nil;
  
  //AppleScript to get all running window titles
  appleScriptFindWindows = [[NSAppleScript alloc] initWithSource:
                                          @"tell application \"System Events\" to get the title of every window of process \"MyProcess\" whose name contains \"Eagle\""];
  
  //Execute and get the result of the OSAScript
  result = [appleScriptFindWindows executeAndReturnError:&amp;error];
  
  //Convert to the result to a string
  NSString *stringResult = [NSString stringWithFormat:@"%@", result];
  
  //I would like to be able to store a comparison variable here such as....
  //NSString *previousResult = stringResult
  
  //If (![previousResult isEqualToString: stringResult]) ....
  //Call a method or return to do stuff 
  </code></pre>
  
  <p>As I am searching every 1s to find new window titles (Who have different identifiers) I need to be able to compare the strings, each time the timer calls getWindowNames, the data is erased (I believe?) so is there something such as a "class" or "global class" variable that is accessible from all methods within my class and keeps the same value I can use for comparisons?</p>
  
  <p>If so or even if not, some help on understanding how to properly structure what I am trying to do will be greatly appreciated.</p>