Search code examples
objective-cnstimernsdatepicker

NSDatePicker, NSTimer with initWithFireDate: fires if I choose a date/time in the past


Not sure I need to paste any code to explain this one, and it's probably something simple that i've overlooked, but i'm seeing my NSTimer with initWithFireDate: fire immediately if I choose a time in the past. This is most likely expected behaviour, but cannot find a mention in the Class Reference for NSTimer.

Thanks!

sc.


Solution

  • Its not that explicit but [1] mentions

    "A timer is not a real-time mechanism; it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer’s firing time has passed. Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds. If a timer’s firing time occurs during a long callout or while the run loop is in a mode that is not monitoring the timer, the timer does not fire until the next time the run loop checks the timer. "

    From the repeated mention of a firing time that may occur during a long callout, I would infer that every timer has a firing time either set directly or indirectly by using an interval. The run loop then checks if any of the firing times are in the past and if so, fires that time, schedules repeats etc. which would result in the behaviour you observed.

    [1] http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html