i'm steve

Namespace Collision in Objective C

Sun 29 Jun 2012

Namespace in programming is like a context for identifiers and functions. You can think of it as a directory. It allows you to have variables/functions that are of the same name but having different meaning in each of the different contexts (e.g. File with the same filename in multiple directories containing different content). The concept is widely-implemented in many existing programming languages, unfortunately Objective C isn’t one of them.

Without namespace, collision often happens when you are including external 3rd party libraries where some of the class objects are duplicated causing sometimes hard-to-trace bug. It might be less of a problem for small app, but it’s daunting if the app is large and complex enough where collision is easy.

Currently, the only way to solve this is by prefixing the duplicated class with your own initials. However, if you are unlucky enough to have adopted multiple closed source libraries which are using the same class object – Good Luck!

* Apple please get namespace adopted into Objective C, like C++ (using namespace std;), Java (package name) and even PHP 5.3.0 (namespace my\namespace;).