MSWeakTimer is a flexible and efficient Objective-C timer library that works on both iOS and OS X platforms. On this page, you will find detailed and update-to-date documentation to help you enhance your understanding and utilisation of MSWeakTimer.
Introduction
MSWeakTimer retains objects with weak references, aiming to mitigate the common problem of strong reference cycles (retention cycles) which developers often face while employing timers. It uses GCD (Grand Central Dispatch) APIs, which makes it especially suitable for multithreaded executions.
Installation
MSWeakTimer can easily be incorporated into your project in a couple of steps:
- Use CocoaPods by adding
pod 'MSWeakTimer'
to your Podfile and then runningpod install
. - Alternatively, you can drag the MSWeakTimer/MSWeakTimer folder into your project.
Usage
Creating an instance of MSWeakTimer is as simple as it gets. Here is a short example of source code:
MSWeakTimer *timer = [MSWeakTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerDidFire:) userInfo:nil repeats:YES dispatchQueue:dispatch_get_main_queue()]; - (void)timerDidFire:(MSWeakTimer *)timer { NSLog(@"Fire!"); }
Features
MSWeakTimer comes with a significant set of features:
- Prevents leverage of strong reference cycles.
- Provides the flexibility of firing from any GCD queue and not only the main queue.
- Automatically invalidates the timer if the target deallocates,
- Has the ability to schedule the execution of a block of code on an arbitrary queue.
Requirements
MSWeakTimer operates with:
- iOS 7.0 or above
- Mac OS X 10.9 or above.
License
MSWeakTimer is released under the MIT license. This means you can use it freely in your projects provided you acknowledge the original source.
Conclusion
In conclusion, MSWeakTimer provides a simple, robust, and efficient solution for developers seeking to avoid the common pitfall of strong reference cycles. Its incorporation into your project enhances the quality, performance, and reliability of your software.