Objective-C function dispatch collisions; Or, how to achieve "namespaces"?

Posted by fbrereto on Stack Overflow See other posts from Stack Overflow or by fbrereto
Published on 2009-09-24T23:04:18Z Indexed on 2010/04/14 22:33 UTC
Read the original article Hit count: 345

I have an application for Mac OS X that supports plugins that are intended to be loaded at the same time. Some of these plugins are built on top of a Cocoa framework that may receive updates in one plugin but not another. Given Objective-C's current method for function dispatching, any call from any plugin to a given Objective-C routine will go to the same routine every time. That means plugin A can find itself inside plugin B with a trivial Objective-C call! Obviously what we're looking for is for each plugin to interact with its own version of the framework upon which it was built. I have been reading some on Objective-C and this particular need, but haven't found a definitive solution for it yet.

Update: My use of the word "framework" above is misleading: the framework is a statically-linked library, built into the plugin(s) that need it. The way Objective-C handles dispatching, however, even these statically linked pieces of disparate code will co-mingle in the Objective-C dispatcher, leading to unintended consequences.

Update 2: I'm still a bit fuzzy on the answer provided here, as it doesn't seem to propose a solution as much as an unproven hypothesis.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about namespace