• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTimer +timerWithTimeInterval:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSTimer +timerWithTimeInterval:
      • From: Steve Mills via Cocoa-dev <email@hidden>
    • Re: NSTimer +timerWithTimeInterval:
      • From: Alex Zavatone via Cocoa-dev <email@hidden>
  • Prev by Date: Re: iOS open In place, permission denied
  • Next by Date: Re: NSTimer +timerWithTimeInterval:
  • Previous by thread: Re: iOS open In place, permission denied
  • Next by thread: Re: NSTimer +timerWithTimeInterval:
  • Index(es):
    • Date
    • Thread