Hello all,
Hope this is the right place to ask (if there is a better development forum please let me know!)
I've got a basic "tick" program that uses an NSTimer, currently running it in a "foundation" app (on the terminal). For some reason NSTimer doesn't seem to be firing:
Output is:
and then it stops running. Any ideas?
Edd
Hope this is the right place to ask (if there is a better development forum please let me know!)
I've got a basic "tick" program that uses an NSTimer, currently running it in a "foundation" app (on the terminal). For some reason NSTimer doesn't seem to be firing:
Code:
#import <Foundation/Foundation.h>
@interface ECMetronome : NSObject
{
NSTimeInterval millisecondsBetweenTicks;
NSTimer *timer;
NSNotificationCenter *notificationCenter;
NSInvocation *invocation;
}
@property (nonatomic, retain) NSTimer * timer;
- (id) initWithMilliseconds: (double) milliseconds;
- (id) initWithMetronomeMark: (double) mark;
- (void) start;
- (void) tick: (NSTimer *)theTimer;
@end
Code:
#import "ECMetronome.h"
@implementation ECMetronome
@synthesize timer;
- (id)init
{
self = [super init];
if (self) {
if (!millisecondsBetweenTicks) millisecondsBetweenTicks = 1000;
NSLog(@"Metronome Initialised - metronome mark:%f", millisecondsBetweenTicks/1000*60);
}
return self;
}
- (id) initWithMilliseconds: (double) milliseconds
{
millisecondsBetweenTicks = milliseconds;
return [self init];
}
- (void) setMetronomeMark:(double)mark
{
millisecondsBetweenTicks = 60000/mark;
}
- (id) initWithMetronomeMark: (double) mark
{
millisecondsBetweenTicks = 60000/mark;
return [self init];
}
- (void) start
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:(millisecondsBetweenTicks/1000) target:self selector:@selector(tick:) userInfo:nil repeats:YES];
NSLog(@"Timer Started");
}
- (void) tick: (NSTimer *)theTimer {
NSLog(@"Tick!");
}
@end
Output is:
Code:
2012-07-27 01:56:07.573 commandLineMetronome[7396:303] Hello, World!
2012-07-27 01:56:07.575 commandLineMetronome[7396:303] Metronome Initialised - metronome mark:60.000000
2012-07-27 01:56:07.575 commandLineMetronome[7396:303] Timer Started
and then it stops running. Any ideas?
Edd