开发者

Restructure code block so that Unused warning is eliminated

开发者 https://www.devze.com 2023-03-27 09:30 出处:网络
Having inherited a project from an Outsourced development company, I\'ve been asked to modify the application and add some features.

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 comme开发者_StackOverflownt 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];
}


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?


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
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号