Skip to content

Instantly share code, notes, and snippets.

@DHowett
Last active December 16, 2015 21:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DHowett/5497730 to your computer and use it in GitHub Desktop.
Save DHowett/5497730 to your computer and use it in GitHub Desktop.
@interface MyAwesomeSingletonPleaseDontNameMeThis: NSObject
+ (id)sharedInstance;
- (void)registerForNotifications;
@end
@implementation MyAwesomeSingletonPleaseDontNameMeThis
+ (id)sharedInstance {
static id _sh;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sh = [[self alloc] init];
});
return _sh;
}
- (void)registerForNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
}
- (void)_applicationDidBecomeActive:(NSNotification *)notification {
// explode or whatever
}
@end
%ctor {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[[MyAwesomeSingletonPleaseDontNameMeThis sharedInstance] registerForNotifications];
[pool drain];
}
@rmsy
Copy link

rmsy commented May 1, 2013

@interface MyAwesomeSingletonPleaseDontNameMeThis: NSObject

That's an interesting naming scheme...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment