简体   繁体   中英

unused variable warning when variable is actually being used

I am given a warning in Xcode that a variable I am using, is not being used:

- (void)timerTicked:(id)sender {
  [timerButton setTitle:[self timerIsActive] ? @"Stop timer" : @"Start Timer" forState:UIControlStateNormal];
  if([self timerIsActive]) {
    NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:timeEntry.startDate];
    double seconds = (int) interval % 60;
    double minutes = (int) interval / 60.0;
    double hours = (int) interval / 60.0 / 60.0;

    [timerLabel setText:[NSString stringWithFormat:@"%.0f hours %.0f minutes %.0f seconds", hours, minutes, seconds]];
  }
}

The variable reported not being used is interval .

Why is interval being reported as unused?

It works fine for me. Try to clean the code and Analyze using shift commond B. -- AV

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM