Skip to content

Instantly share code, notes, and snippets.

@mkhl
Created April 25, 2009 01:52
Show Gist options
  • Save mkhl/101454 to your computer and use it in GitHub Desktop.
Save mkhl/101454 to your computer and use it in GitHub Desktop.
// Getting Loaded
// Source: http://googlemac.blogspot.com/2006/11/getting-loaded.html
@implementation Foo (FooBarAdditions)
...
@end
@interface Foo (FooBarAdditionsPrivateMethods)
+ (void) initializeBar;
@end
@implementation Foo (FooBarAdditionsPrivateMethods)
+ (void) initializeBar {
// Initialize stuff here
}
@end
void __attribute__ ((constructor)) InitializeFooBar(void) {
static BOOL wasInitialized = NO;
// safety in case we get called twice.
if (!wasInitialized) {
[Foo initializeBar];
wasInitialized = YES;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment