NSTimer provides an easy to use timer API, but issues arise when working with GCD.
Here’s an NSTimer replacement from Javier Soto of Mindsnacks that provides a nice simple syntax like NSTimer but doesn’t retain the target, and can be used by GCD queues thus removing the need for you to work directly with dispatch_source when you need timers for a GCD thread.
As the readme states:
The first motivation for this class was to have a type of timer that objects could own and retain, without this creating a retain cycle ( like NSTimer causes, since it retains its target ). This way you can just release the timer in the -dealloc method of the object class that owns the timer.
More often than not, an object needs to create a timer and invalidate it when a certain event occurs. However, doing this when that object works with a private GCD queue gets tricky. This timer object is thread safe and doesn’t have the notion of run loop, so it can be used with GCD queues and installed / invalidated from any thread or queue.
You can find NSWeakTimer on Github here.
A nice easy timer class that works with GCD.
Submit A Resource
Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?
You can submit the url here.
The resources we feel will appeal to our readers the most will be posted on the front page.