This is how my code looks currently
NSTimer *delayTimer;
delayTimer = [NSTimer scheduledTimerWithTimeInterval:0.01
target:self
selector:@selector(longRunner)
userInfo:nil
repeats:NO];
// [delayTimer invalidate];
If I run this through build and analyze I get the following warning
Value stored in delayTimer is never read.
I understand the message and what it means but can’t really figure out how to stop it appearing. Are there some analyzer messages ok to ignore?
I tried adding the commented invalidate code, but as expected this ran before the timer so the timer didn’t.
It is never a good idea to ignore warnings. You have two options in this case:
Store the timer in a property. This is the better option as it allows you to destroy the timer if the object that created it is destroyed before the timer fires.
Don’t create a local variable. This is the actual warning. Since you are not using the pointer ‘delayTimer’ then just don’t assign it.
Option 1 is the right answer. Option 2 will remove the warning.