Skip to content

Instantly share code, notes, and snippets.

@jinthagerman
Created October 2, 2012 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jinthagerman/3815780 to your computer and use it in GitHub Desktop.
Save jinthagerman/3815780 to your computer and use it in GitHub Desktop.
Singletons
@implementation MySingleton
+ (MySingleton*)singleton {
static MySingleton* __singleton = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
__singleton = [[MySingleton alloc] init];
});
return __singleton;
}
@end
OR
@implementation MySingleton
+ (id)singleton {
static MySingleton* __singleton = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
__singleton = [[MySingleton alloc] init];
});
return __singleton;
}
@end
@jonathanhoskin
Copy link

First one. With a "@Class MySingleton;" above the @interface.

@jonathanhoskin
Copy link

"@Class MySingleton;" I mean.

@jonathanhoskin
Copy link

Shit. @Class with a lower case c.

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