Re: Why the need for the id type?
Re: Why the need for the id type?
- Subject: Re: Why the need for the id type?
- From: "Daniel T. Staal" <email@hidden>
- Date: Mon, 18 Jun 2007 17:13:24 -0400 (EDT)
- Importance: Normal
On Mon, June 18, 2007 5:01 pm, mmalc Crawford said:
>
> On Jun 18, 2007, at 1:46 PM, Wagner Truppel wrote:
>
>> I don't understand why id should be necessary. Why isn't NSObject
>> (or some other root class) enough?
>>
> <http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_3.html#//apple_ref/doc/uid/TP40002974-CH4-DontLinkElementID_130
> >
>
> mmalc
I'm not sure that page has a clear answer the question being asked:
Wagner, as I understand it, feels that NSObject could be used for dynmic
typing, since an item declared to be of it's class can be any of it's
subtypes.
id, as I understand it, isn't quite the same however: An NSObject object
containing an NSObject subclass is an NSObject, to the code. It happens
to respond to it's 'true' classes' methods, but it is still an NSObject.
An id on the other hand can be _any_ class. If you pass it an
NSAcmeWidget the resultant object is an NSAcmeWidget, not just an NSObject
that happens to behave like an NSAcmeWidget. A subtle distiction, but...
Basically, _id_ says that this object will be dynamically typed. Anything
else is statically typed, even if isn't being used as it's 'true' type.
Clearer?
Daniel T. Staal
---------------------------------------------------------------
This email copyright the author. Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes. This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden