Reputation: 25665
How do you get code in a framework to execute when that framework is loaded under iOS?
The application Reveal (http://revealapp.com) uses this technique (combined with listening out for the UIApplicationDidFinishLaunchingNotification
notification).
Upvotes: 4
Views: 365
Reputation: 26558
You have two possibilities.
Use a +load
method either in one of your own class or add it on a category on an existing class. For example:
@implementation MyClass
+ (void) load
{
// Your initialization code
}
@end
Use __attribute__((constructor))
on a function. For example:
__attribute__((constructor)) void MyLibraryInitialize(void)
{
// Your initialization code
}
Beware: both methods will execute your code before the main
function is called.
Upvotes: 4