• 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
Re: Rescheduling an NSTimer from a completion method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rescheduling an NSTimer from a completion method


  • Subject: Re: Rescheduling an NSTimer from a completion method
  • From: Fritz Anderson <email@hidden>
  • Date: Wed, 12 Aug 2009 11:17:04 -0500

On 12 Aug 2009, at 10:55 AM, Christopher Kane wrote:

On Aug 11, 2009, at 10:28 AM, Fritz Anderson wrote:

iPhone OS 3.0

Can an NSTimer be rescheduled after firing, and after another trip through the run loop?

I'd like to "reschedule" a NON-repeating timer in my own code. I assume that in the simple case it would be something like:

- (void) handleTimer: (NSTimer *) aTimer
{
// ... do things ...
[aTimer setFireDate: someTimeInTheFuture];
[[NSRunLoop currentRunLoop] addTimer: aTimer forMode: NSDefaultRunLoopMode];
}


I'm pretty sure that this is legal — am I right?

No, as you suspected farther down in your message. NSTimers which are not repeating are one-shot -- they cannot be rescheduled. Create a new NSTimer, when you next need it, and add it to the run loop. [And also self.myTimerIvar = nil; in your timer handler as you thought.]

Thank you very much indeed.

I think I'll file a radar on the documentation. My reading of the class overview suggested to me that if the run loop could reschedule repeating timers, I could reschedule a non-repeating one.

It does say, "If you specify that the timer should not repeat, it is automatically invalidated after it fires," but elsewhere "invalidate" is said to mean that it's removed from the run loop's queue -- which suggested to me that it could be revalidated by putting it back.

But now I understand, and I thank you kindly for your help.

	— F

_______________________________________________

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


References: 
 >Rescheduling an NSTimer from a completion method (From: Fritz Anderson <email@hidden>)
 >Re: Rescheduling an NSTimer from a completion method (From: Christopher Kane <email@hidden>)

  • Prev by Date: Re: Rescheduling an NSTimer from a completion method
  • Next by Date: Re: Intel Mac prefpane error
  • Previous by thread: Re: Rescheduling an NSTimer from a completion method
  • Next by thread: Possible to work around 10.4 LaunchAgent bugs?
  • Index(es):
    • Date
    • Thread