I am trying to compare two NSDates one is created by the viewDidLoad method and the other by clicking a button. I want to be able to click the button and find the time difference since the viewDidLoad was ran. I keep getting a difference of nil. Any Ideas?
#import "TimeViewController.h"
id startTime;
@implementation TimeViewController
- (void)viewDidLoad {
NSDate *startTime = [NSDate date];
NSLog(@"startTime = %@",startTime);
}
- (IBAction)buttonPressed{
NSDate *now = [NSDate date];
NSLog(@"now = %@",now);
double timeInterval = [now timeIntervalSinceDate:startTime];
NSLog(@"time difference = %@",[NSString stringWithFormat:@"%g",timeInterval]);
}