Reputation: 874
I am having so much trouble with NSTimers. I have used them before, but this timer just does not want to fire.
-(void) enqueueRecordingProcess
{
NSLog(@"made it!");
NSTimer *time2 = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(warnForRecording) userInfo:nil repeats:YES];
}
-(void) warnForRecording
{
NSLog(@"timer ticked!");
if (trv > 0) {
NSLog(@"Starting Recording in %i seconds.", trv);
}
}
I don't see why this won't run. I even tried this:
- (void)enqueueRecordingProcess
{
NSLog(@"made it!");
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(warnForRecording) userInfo:nil repeats:YES];
}
- (void)warnForRecording
{
NSLog(@"timer ticked!");
}
What is wrong?
Upvotes: 0
Views: 392
Reputation: 429
// Yes. Here is sample code (tested on OS X 10.8.4, command-line).
// Using ARC:
// $ cc -o timer timer.m -fobjc-arc -framework Foundation
// $ ./timer
//
#include <Foundation/Foundation.h>
@interface MyClass : NSObject
@property NSTimer *timer;
-(id)init;
-(void)onTick:(NSTimer *)aTimer;
@end
@implementation MyClass
-(id)init {
id newInstance = [super init];
if (newInstance) {
NSLog(@"Creating timer...");
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(onTick:)
userInfo:nil
repeats:YES];
}
return newInstance;
}
-(void)onTick:(NSTimer *)aTimer {
NSLog(@"Tick");
}
@end
int main() {
@autoreleasepool {
MyClass *obj = [[MyClass alloc] init];
[[NSRunLoop currentRunLoop] run];
}
return 0;
}
Upvotes: 0
Reputation: 14549
I am not sure about you specifics, but you need to service the runloop in order to get events, including timers.
Upvotes: 0