[cfe-dev] Adding namespaces to Objective-C

Douglas Gregor dgregor at apple.com
Wed Nov 10 08:03:59 PST 2010


On Nov 10, 2010, at 2:31 AM, Jean-Daniel Dupas wrote:

> 
> Le 10 nov. 2010 à 01:51, Chris Lattner a écrit :
> 
>> 
>> On Nov 9, 2010, at 3:50 PM, Owen Shepherd wrote:
>> 
>>>> Would declare the Object class in the global namespace as NSObject, and in the Foundation namespace as Foundation!Object.  The runtime functions for iterating over classes would only see the version in the global namespace and a set of new functions would provide introspection.
>>> 
>>> The :: syntax is unambiguous, familiar, and common with that of C++. I see no reason to be distinct for the sake of it. As for short aliases, I see no reason why one could not do
>>> 
>>> namespace Foundation { @interface Object ... }
>>> using NSObject = Foundation::Object;
>>> 
>>> Longer? Slightly. However, it provides the option to avoid polluting the global namespace in the general case, something which is always useful.
>> 
>> FWIW, :: is not a token in ObjC.
> 
> No, but it may be used in selector.
> 
> @selector(foo::::) is a valid selector. So, if namespace applies to selector too, you will have to figure a way to define qualified selector name.

Or side-step the problem by using something other than "." in the equivalent of nested-name-specifiers.

	- Doug



More information about the cfe-dev mailing list