1

Having inherited a project from an Outsourced development company, I've been asked to modify the application and add some features.

Being a bit of a perfectionist (but still relatively new) I'm trying to eliminate Warnings from the Project when I compile.

I'm getting this error

Unused variable 'timer' at the end of a function

Which is setting a refresh button back to enabled after the timeout.

How can I rework this so that I don't get the unused (I can't comment it out, because it's actually doing what it's supposed to by resetting the state after the timer elapses)..

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    //lots of previous code
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(enableRefresh) userInfo:nil repeats:NO];
}
jv42
  • 8,521
  • 5
  • 40
  • 64
Paul Farry
  • 4,730
  • 2
  • 35
  • 61

3 Answers3

1

Just remove the assignment and have it read:

[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(enableRefresh) userInfo:nil repeats:NO];

Without the NSTimer *timer =.

Apparently the pointer to the timer object just isn't needed because it simply does what it is supposed to do right away. Or am I missing something?

double-m
  • 118
  • 8
0

If you still need reference to that timer later in that method do:

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    //lots of previous code
NSTimer *timer;
timer=[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(enableRefresh) userInfo:nil repeats:NO];

    //lots of other code
}
kviksilver
  • 3,824
  • 1
  • 26
  • 27
0

There is always the fake operation:

(void)timer;

I used it a lot to avoid unused parameter warnings, to the point of making it a macro.

jv42
  • 8,521
  • 5
  • 40
  • 64