NSTimer +timerWithTimeInterval:
NSTimer +timerWithTimeInterval:
- Subject: NSTimer +timerWithTimeInterval:
- From: Carl Hoefs via Cocoa-dev <email@hidden>
- Date: Wed, 29 Apr 2020 13:36:23 -0700
When I issue NSTimer's +timerWithTimeInterval::::: method, I'm getting
unexpected timer firing times (20X faster than expected).
∙ If I specify 1.0 for the time interval, my method gets called 20 times/sec.
∙ If I specify 20.0 for the time interval, my method gets called 1 time/sec.
∙ If I specify 100.0 for the time interval, my method gets called 5 times/sec.
...etc.
Here is my only invocation, called once and nevermore:
NSTimer *newTimer = [NSTimer timerWithTimeInterval:1.0 // should be
1/sec
target:self
selector:@selector(newData:)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:newTimer
forMode:NSRunLoopCommonModes];
How can this be? NSTimeInterval is supposed to be in seconds!
From the Apple documentation:
+ (NSTimer
<https://developer.apple.com/documentation/foundation/nstimer?language=objc>
*)timerWithTimeInterval:(NSTimeInterval
<https://developer.apple.com/documentation/foundation/nstimeinterval?language=objc>)ti
target:(id)aTarget
selector:(SEL)aSelector
userInfo:(id)userInfo
repeats:(BOOL)yesOrNo;
Parameters
ti
The number of seconds between firings of the timer. If ti is less than or equal
to 0.0, this method chooses the nonnegative value of 0.0001 seconds instead. A
NSTimeInterval value is always specified in seconds; it yields sub-millisecond
precision over a range of 10,000 years.
I can accommodate this odd behavior in my code, but something's gotta be
wrong...
-Carl
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden