Re: Usage of +class
Re: Usage of +class
- Subject: Re: Usage of +class
- From: Jonathon Mah <email@hidden>
- Date: Sun, 23 Apr 2006 01:12:07 +0930
On 2006-04-22, at 19:17, j o a r wrote:
Not really. You can find the answer in The Fine Manual:
Ah, thanks joar. To sumarize:
A class identifier has two uses: a _type_, and a message receiver.
Contrast this to a variable, which has two uses: a _value_, and a
message receiver.
e.g.
{
NSString *str; // Class used as a type
NSLog(@"Class address: %u", [NSString class]); // Class used as
a receiver
NSLog(@"Class address: %u", NSString); // INVALID: NSString has
no value
id obj = [NSArray array];
NSLog(@"Object address: %u", obj); // Object used as a value
NSLog(@"Object description: %@", [obj description]); // Object
used as a receiver
obj *blah; // INVALID (obviously): obj is not a type
}
Interestingly, you can change the use of a class name from a type to
a value:
{
Class temp = [NSString class];
void *NSString = temp;
NSString *str; // INVALID: NSString is not a type
NSLog(@"Class address: %u", [NSString class]); // Valid (but
warning)
NSLog(@"Class address: %u", NSString); // Valid
}
I think I've beaten this to death now.
Jonathon Mah
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden