Subclassable Objective-C singleton for Mac OSX and iOS
Objective-C Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
DOSingleton.xcodeproj
DOSingleton
Tests
.gitignore
.travis.yml
DOSingleton.podspec
LICENSE.md
README.md

README.md

DOSingleton

Version License Platform Build Status

DOSingleton is a subclassable Objective-C singleton for Mac OSX and iOS.

Ussage

Copy files

Copy the following files to your project:

  • DOSingleton/DOSingleton.h
  • DOSingleton/DOSingleton.m

DOSingleton is also available on CocoaPods

Subclass

DOSingleton is designed for subclassing, you should subclass it to make your own singleton:

#import "DOSingleton.h"

@interface MySingleton : DOSingleton {
	NSString *foo;
}

- (void)printFoo;	

@end

When subclassing DOSingleton you should think about your subclass as an ordinary class, DOSingleton makes sure that there is only one instance of your class.

If you want to make your own initializer or override -init method your should check whether your singleton has already been initialized with isInitialized property to prevent repeated initialization.

#import "MySingleton.h"

@implementation MySingleton

- (id)init
{
	if (!self.isInitialized) {
		self = [super init];

		if (self) {
			// Initialize self.
		}
	}
 
	return self;
}

- (void)printFoo
{
	NSLog(@"%@", foo);
}

@end

Then you can get the shared instance of your singleton with +sharedInstance methods:

[[MySingleton sharedInstance] printFoo];

Requirements

DOSingleton uses ARC.

Documentation

http://cocoadocs.org/docsets/DOSingleton

License

DOSingleton is available under the MIT license. See the LICENSE.md file for more info.

Feel free to use it and contribute!