Skip to content

Instantly share code, notes, and snippets.

@v5tech
Last active August 29, 2015 14:06
Show Gist options
  • Save v5tech/4ad1807a68b1666860e2 to your computer and use it in GitHub Desktop.
Save v5tech/4ad1807a68b1666860e2 to your computer and use it in GitHub Desktop.
iOS: The singleton pattern
#import <Foundation/Foundation.h>
@interface Person : NSObject
+ (id)sharedInstance;
@end
+ (id)sharedInstance {
static Person *theSharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
theSharedInstance = [[self alloc] init];
});
return theSharedInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment