[cfe-dev] Adding namespaces to Objective-C

Jean-Daniel Dupas devlists at shadowlab.org
Tue Nov 9 16:09:41 PST 2010


Le 9 nov. 2010 à 23:35, Blaine Garst a écrit :

> On Nov 9, 2010, at 1:54 PM, Owen Shepherd wrote:
> 
>>> 
>>> Adding namespaces to ObjC is a huge minefield, not something to be done lightly.  If you'd really really like to pursue it, please start by writing out a spec/proposal of how you think it should work along with the corner cases enumerated.
>> 
>> I am drafting one now, though it may take a while.
>> 
>> The hardest aspect seems to be namespacing of selectors; it seems to be an issue which I haven't really seen affecting other languages, and seems a rather difficult one to solve elegantly, though I must ask: Is it a major issue in practice? I haven't found it to be, and haven't found other people claiming it to be either, though I don't claim that it doesn't exist. 
> 
> I have had a spec for this for several years.
> 
> The gist is that methods are defined by the protocol, class, or category, and are currently implicitly reused; syntax would have to be added to disambiguate re-use (i.e. @overrides or equivalent) from introductory use, and to occasionally explicitly name the source of the method being used (for example, -copy is defined in NSObject from the NSCopying protocol, but NSObject does not conform to the NSCopying protocol; 

FWIW, NSCopying defines only one method which is -copyWithZone:. -copy is not defined in NSCopying, this is just a convenient NSObject's method that return [self copyWithZone:nil] or raises an exception.
That's why I always use copyWithZone:nil in my code. It allows the compiler to detect if you try to copy an object that do not conform to NSCopying.

-- Jean-Daniel








More information about the cfe-dev mailing list