Re: Retyping parameters
Re: Retyping parameters
- Subject: Re: Retyping parameters
- From: Matt Neuburg <email@hidden>
- Date: Sun, 03 Jul 2005 08:58:30 -0700
On Fri, 1 Jul 2005 14:17:23 +0100, "Theodore H. Smith" <email@hidden>
said:
>I can implement like this:
>
>- (BOOL)outlineView:(NSOutlineView *)ov isItemExpandable:
>(TaxonomyNode*)item {
> if (item == nil) { return true; }
> return [item expandable];
>}
>
>Here, I have declared item to be "TaxonomyNode*" instead of an "id".
That's what an "id" is. It's something that fits any type. Like a pointer to
void, or type O blood.
>I am just asking, is there any reason to avoid doing this?
No - in fact, it's a good idea, because the coercion enables compile-time
type checking within your method. The alternative is to assign "item" to a
TaxonomyNode* in the first line:
>- (BOOL)outlineView:(NSOutlineView *)ov isItemExpandable:
>(id)item {
> TaxonomyNode* tn = item;
> if (tn == nil) etc.
But your approach is more elegant. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
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