Don't understand the target-action example


#1

Hi,

I don’t understand why the BNLogger class has a property lastTime and also a method lastTimeString in it.

Wouldn’t it be easier to put all of that into the method updateLastTime?
I mean like that:

-(void)updateLastTime:(NSTimer *)t {
	static NSDateFormatter *dateFormater = nil;
	
	if (!dateFormater) {
		dateFormater = [[NSDateFormatter alloc] init];
		[dateFormater setTimeStyle:NSDateFormatterMediumStyle];
		[dateFormater setDateStyle:NSDateFormatterMediumStyle];
		NSLog(@"Created dateFormater.");
	}
        NSDate *now = [NSDate date];
	NSLog(@"Time is: %@", [dateFormater stringFromDate:now]);
}

The code above does the same thing and it is less typing. Can you explain what is better in the example in the book please?

Thanks
Rob