This is a singleton class for iOS, Objective-C, Cocoa Touch, iPhone, iPad.
- Used in production
- Subclassible (to the n-th degree)
- ARC compatible
- Safe with
- Loaded lazily
- Lock-free (uses +initialize, not @synchronize)
This implementation "loads lazily" (which is good). It does not "require explicit initialization" and it does not "lock to allocate". This implementation eliminates the iOS singleton boilerplate.
- Add the files to your project
- Import the header using
- Subclass the KLSingleton class in the following way:
@interface MYSubclass : KLSingleton
You may then retrieve the unique, ready-to-use instance of your class by calling any of the following methods:
[MYSubclass instance] [MYSubclass sharedInstance] //alias [MYSubclass singleton] //alias [[MYSubclass alloc] init] //bad style, but safe to call any number of times
Released under ISC (similar to 2-clause BSD)