Possible Duplicate:
What is the best way to solve an Objective-C namespace collision?
I have develop a third-party dynamic library for iphone, depends on Mobile Substrate.
The problem is that if some APP have a Obj-C class named “Class1”, while my dylib also have a class named “Class1”, there is no guarantee that which class will be used at run time.
Is there any solution that I can keep the class name “Class1” and solve the namespace problem?
In Objective-C the concept of namespace doesn’t exist, source files are simply imported one in another and this of course can cause name collisions if common name are used as class name.
A good way to solve collision problems in Objective-C is adopt a prefix to differentiate your class name from other class names, and this is the technique already used by Apple itself, lets think about the array class, it is called NSArray, why ?
There is a specific reason behind that :
NextStep is the name of the company that created the Foundation framework, and the company that was acquired by Apple in the mid 90’s.
I’m for example using a different prefix for my classes that I pack in libraries, I use : AleArray first 3 characters of my name followed by the name of the data structure, you can choose your own prefix and go ahead with that …
Of course, the probability of a collision using a simple prefix still higher than using namespaces(that usually use a reverse domain name notation), but could be enough in most situations.