Re: timeIntervalSinceDate ????
Re: timeIntervalSinceDate ????
- Subject: Re: timeIntervalSinceDate ????
- From: Stefan Jung <email@hidden>
- Date: Thu, 27 Sep 2001 12:22:55 +0200
There are three problems.
On Donnerstag, September 27, 2001, at 03:10 Uhr, KyooHo Lee wrote:
NSDate *oldDate;
NSDate *currentDate;
NSDate *intervalDate;
NSTimeInterval intervalDate; or more obvious: intervalTime.
- (IBAction)start:(id)sender {
oldDate = [NSCalendarDate calendarDate];
oldDate = [[NSCalendarDate calendarDate] retain];
[sender setTitle : @"stop"];
[sender setAction : @selector(stop:)];
[startField setObjectValue : oldDate];
}
- (IBAction)stop:(id)sender {
currentDate = [NSCalendarDate calendarDate];
[sender setTitle : @"start"];
[sender setAction : @selector(start:)];
[stopField setObjectValue : currentDate];
intervalDate = [currentDate timeIntervalSinceDate:oldDate];
Three problems:
1. timeIntervalSinceDate: returns an NSTimeInterval which is essentially
a double and not an object of class NSDate.
2. oldDate is probably released, because the calendarDate method gives
you autoreleased object, so you hav to retain it, and release it
afterwards on your own. So you don't get a signal 10 SIGBUS error,
because oldDate was already released by the autorelease pool.
[secondsField setObjectValue : intervalDate];
3. As intervalDate is NOT an object but a double (or NSTimeInterval),
you have to make an object out of it.
[secondsField setObjectValue: [NSNumber numberWithDouble:
intervalDate]];
This works!
Fast advance,
Stefan Jung