9

I have an NSTimer that I initialize with scheduledTimerWithTimeInterval: with a very short interval (.1 seconds) with no repeat, and then never use it again as it invalidates itself and therefore releases its retain on the target. Xcode warns that it is an unused variable, and I was curious if there was a sensible way to get rid of the warning (The yellow upsets my eyeballs!)

Thanks.

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
Jesse Naugher
  • 9,780
  • 1
  • 41
  • 56

2 Answers2

23

if you don't use it again don't save it in a variable.

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

will work perfectly fine

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
2

Just don't assign the result to anything if you aren't going to use the return value.

[NSTimer scheduledTimerWithTimeInterval:...];
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005