Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Xcode 4 mark variables as unused even if they are?

I'm instantiating and scheduling a timer variable but Xcode compiler and analyzer marks my var "levelScoreTimer" with 2 warnings like "warning: unused variable 'levelScoreTimer' and "Dead store: Value stored to 'levelScoreTimer' during its initialization is never read". What is wrong with my declaration? The scheduledTimerWithTimeInterval method instantiates and puts the timer on the main run loop. I'm also stopping the timer from selector method inside, so the timer as objects is used for sure. Sometimes in similar cases I break the line into two lines by declaring a type for variable on the first line and making assignment on the second line. But it is not a solution for timer object. Any suggestions? Here is my declaration and assigment:

NSTimer *levelScoreTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateTotalScoreLabelFromTimeLeftLabel:) userInfo:nil repeats: YES];
like image 906
Centurion Avatar asked Aug 10 '11 11:08

Centurion


1 Answers

Change the code from

NSTimer *levelScoreTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateTotalScoreLabelFromTimeLeftLabel:) userInfo:nil repeats: YES];

to

[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateTotalScoreLabelFromTimeLeftLabel:) userInfo:nil repeats: YES];
like image 85
dasdom Avatar answered Oct 04 '22 18:10

dasdom