I think I put this into my code according to the book but the compiler generates a “No known class method” error for scheduledTimerWithTimerInterval, even though it proposes it when I type it in. Is this a method that isn’t there any more?
[code]#import <Foundation/Foundation.h>
#import “BNRLogger.h”
int main(int argc, const char * argv[]) {
@autoreleasepool {
BNRLogger *logger = [[BNRLogger alloc]init];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0
target:logger
selector:@selector(timerFireMethod)
userinfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop]run];
}
return 0;
}
[/code]
[code]#import <Foundation/Foundation.h>
@interface BNRLogger : NSObject
@property (nonatomic) NSDate *lastTime;
-(NSString *)lastTimeString;
-(void)timerFireMethod: (NSTimer *)t;
@end[/code]
[code]
#import “BNRLogger.h”
@implementation BNRLogger
-(NSString *)lastTimeString
{
static NSDateFormatter *dateFormatter = nil;
if (!dateFormatter)
{
dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSLog(@“created dateFormatter”);
}
return [dateFormatter stringFromDate:self.lastTime];
}
-(void)timerFireMethod:(NSTimer *)t;
{
NSDate *now = [NSDate date];
[self setLastTime:now];
NSLog(@“Just set time to %@”, self.lastTimeString);
}
@end[/code]