Ohhhh ... funny question. The answer is c-ism.
Consider:
@interface MyClass : NSObject @end @implementation MyClass @end
Now let's say you have:
... MyClass *m = nil; ...
In this context, the compiler sees MyClass as a type definition. * says the variable m is pointer to a hunk o' memory that contains one (or many -- don't forget your C pointer-fu) MyClass instances .
In other words, MyClass is a type.
But in the context of something like:
[someInstance isKindOfClass: x ]
x must be an rvalue or, from a human point of view, the value of an expression. However, the type cannot be used as an rvalue.
The fact that the [MyClass class] works is actually a bit hacked, both in the language and on the compiler, in that the grammar specifically allows the type name to be the receiver of messages (to be the target of a method call).
And essentially you can do:
typedef MyClass Foo; .... [MyClass class]; [Foo Class];
Everything will work. However, you cannot do the following, but the error message lights up:
[NSUInteger class];
error: "NSUInteger is not an Objective-C class name or alias
Now, why not have a special occasion everywhere as a bare name?
This combines type names and rvalues, and you quickly have to swallow something like [foo isKindOfClass: (MyClass)]; while barfing on [foo isKindOfClass: (MyClass *)]; which then encroaches on the simulation territory is rather inconvenient.
bbum Jun 24 '10 at 5:03 2010-06-24 05:03
source share