View Full Version : Mutable NSTimer?

2006-05-07, 17:06
So, I've been writing a little app that periodically checks the CPU temperature and displays it in the menu bar. Now I'd like the user to be able to change the interval (frequency) of the gauging. I'm using NSTimer's scheduledTimerWithTimeInterval; however, it appears there is no way to change the interval later on. I figure I'm supposed to invalidate the timer and create a new one, but I'm currently at a loss regarding implementing that. Namely, it seems that the old timer doesn't immediately destroy itself, so for a short time, I have two timers running, which is definitely not what I want.

I would much prefer being able to change the original timer's interval instead, rather than having to create multiple ones. I haven't found much documentation on this, surprisingly, so I'm wondering if anyone has experience. :)

2006-05-08, 15:16
No ideas?

2006-05-11, 21:54
Figured it out (by releasing and reallocating). Not necessarily happy with this solution, but whatever.

2006-05-12, 04:14
Figured it out (by releasing and reallocating).
I was going to suggest that, but I figured it was too obvious. Next time, I won't assume anything! :)

(Yes, I agree it's not very elegant either.)

2006-05-12, 06:56
I was going to suggest that, but I figured it was too obvious.

Oh, I agree that it's obvious that it can be done that way. I was just hoping for something more elegant and was convinced that this wasn't the preferred way™. But according to #macdev, it is.