• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: DragNDropOutlineView Example Define Syntax
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DragNDropOutlineView Example Define Syntax


  • Subject: Re: DragNDropOutlineView Example Define Syntax
  • From: Corbin Dunn <email@hidden>
  • Date: Mon, 27 Jun 2005 09:42:08 -0700

SimpleTreeNode* treeNodeItem = (SimpleTreeNode*)item;

Is this a way to cast the item as a SimpleTreeNode instance named
treeNodeItem?  I don't recognize that syntax statement.  Would another
of saying that be:

Yes..it is, but let me elaborate. The compiler will also accept (with no warnings):


SimpleTreeNode* treeNodeItem = item;

Since item is type (id).

In fact, the compiler will also compile both of these without warnings:

[treeNodeItem childAtIndex:index];
[item childAtIndex:index];

So, why use the former (typed message calls) vs. the latter (untyped id message calls)? Ultimately, the same code is generated.

Two reasons.

1. Compile time type checking

Consider this:

    [treeNode stringValue];
    [item stringValue];

Both items will compile, but the first line will give a warning that "SimpleNodeData may noit respond to -stringValue" (which is true!). The first line you could catch the error at compile time, and correct it. If you used the second line, the problem would only come up at runtime.

2. Code Insight

Consider this:

    [treeNode |

The cursor is at the |. Press Escape (or whatever combo invokes Code Insight / Code Sense in your Xcode -- I have mine set to ctrl-space because it is faster to type).

What you see is a list of messages that the SimpleNodeData type accepts. Cool; you can type down and find the one you want very quickly.

Repeat with:

    [item |

What you see is a list of messages that the "id" type accepts (which is HUGE!). It is more difficult to pick the right method that you want to call.

--corbin



SimpleTreeNode* item = [[SimpleTreeNode alloc] initWithObject:item];

I am assuming it is a type of casting that is going on here?
Thanks again!

_______________________________________________ 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
References: 
 >DragNDropOutlineView Example Define Syntax (From: Ronnie O <email@hidden>)
 >Re: DragNDropOutlineView Example Define Syntax (From: Corbin Dunn <email@hidden>)
 >Re: DragNDropOutlineView Example Define Syntax (From: Ronnie O <email@hidden>)

  • Prev by Date: Re: How do I create a NSArray of NSString constants?
  • Next by Date: Re: How do I create a NSArray of NSString constants?
  • Previous by thread: Re: DragNDropOutlineView Example Define Syntax
  • Next by thread: Re: DragNDropOutlineView Example Define Syntax
  • Index(es):
    • Date
    • Thread