Building Objective-C static libraries with categories

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

I just came across the usage of Linker flag -all_load and -ObjC

Basically, this is used in situations where you build a static library with Categories. When this static library is linked with the actual implemenation / application that use this library, -ObjC linker flag would inform the compiler to load all the Objective C classes implementation.

However, since there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories, we should use -all_load or -force_Load Linker flags.

For More Details. See Apple Technical QA QA1490

Quick Tip : Initializing static variables of a class in Objective C

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Initializes the receiver before it’s used (before it receives its first message).

 

+ (void)initialize


Discussion The runtime sends initialize to each class in a program exactly one time just before the class, or any class that inherits from it, is sent its first message from within the program. (Thus the method may never be invoked if the class is not used.) The runtime sends the initialize message to classes in a thread-safe manner. Superclasses receive this message before their subclasses.


[Reference : NSObject Class Reference]

You can place all your static member variable initialization code in this method as it guarantees it would be called only once BEFORE any method in that Class is invoked through any of its objects.

Happy Coding 🙂