I’ve been looking around for a NSTimer replacement. Mostly to avoid needing to make sure the timer is running on a runloop and that your running the timer in a suitable mode. All of the replacements use gcd and queues.

I’ve found a number of possible replacements, but one in particular looks like the one to go for. The three others use the main thread and I want to get away from the main thread. It is easy enough to send a update ui message back to the main thread once the required work has been done.

I like the simplicity of this NSTimer replacement, it doesn’t require a new class instead everything is wrapped up nicely in a block and it will keep on firing until the object that it fires the doSomething message to no longer exists. What I don’t like is that the code is run on the main thread.

This nice simple timer class is also good, but it also runs on the main thread.

Finally I come to MSWeakTimer. I’m in the process of including it in my project so I’ll report back when I’m done. It is more complicated than the other timers but it is not dependent on the runloop or the main queue.

Report Back

MSWeakTimer seems to be working as expected. I needed to make a couple of small changes to get rid of warnings. I’ve got no warnings in my current project and I’m hoping to keep it that way.

Tags: , , ,