You are currently looking at an older section of the wincent.com website.
Please check the new version of the site at https://wincent.com/ for updated content.

wincent Wincent Colaiuta's weblog

« A moment's reflection | Main | HOM improvements »

November 29, 2006

Google gems

The Google Mac Weblog continues to be an occasional source of some very interesting gems. This time it's about module initializers, something which I didn't know existed. A handy replacement for the load method in categories with a better-defined execution order from which you can safely call methods in super classes and other classes.

Basically, it's not entirely safe to send any Objective-C message from inside load because there are no guarantees. In practice, on the current version of Mac OS X, it is safe to send messages to your superclass because the runtime will load them and initialize them for you if necessary, but that could change with any future version of the OS. Likewise I've never had a problem sending messages to Cocoa classes from inside load but that could change too.

So the module-level constructors and destructors are a welcome solution.

More Development articles

Posted by wincent at November 29, 2006 8:57 AM