• 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: Ronnie O <email@hidden>
  • Date: Sat, 25 Jun 2005 12:49:50 -0500

Thanks for breaking that down for me.  I am can say that I ALMOST
completely get it.  The following line is throwing me off though:

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:

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

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


On 6/24/05, Corbin Dunn <email@hidden> wrote:
> > This is probably more of a C or Objective C syntax question than an
> > OutlineView question, but can anyone explain to me what is going on
> > with the following defintion statements in the DragNDropOutlineView
> > example (this is in the Developer Examples Folder):
> >
> > // Conveniences for accessing nodes, or the data in the node.
> > #define NODE(n) ((SimpleTreeNode*)n)
> > #define NODE_DATA(n) ((SimpleNodeData*)[NODE((n)) nodeData])
> > #define SAFENODE(n) ((SimpleTreeNode*)((n)?(n):(treeData)))
>
> Well, these are macros, which are expanded by the C preprocessor.
> Anytime you see NODE(n), it is replaced with ((SimpleTreeNode*)n),
> where n is the variable passed into the macro. It just saves some
> typing.
>
> For example, this line:
>
> - (id)outlineView:(NSOutlineView *)olv child:(int)index ofItem:(id)
> item {
>      return [SAFENODE(item) childAtIndex:index];
> }
>
> Could have been (typed in mail):
>
> - (id)outlineView:(NSOutlineView *)olv child:(int)index ofItem:(id)
> item {
>      return [((SimpleTreeNode*)((item)?(item):(treeData)))
> childAtIndex:index];
> }
>
> But, to understand it better, this is the same logic:
>
> - (id)outlineView:(NSOutlineView *)olv child:(int)index ofItem:(id)
> item {
>      SimpleTreeNode* treeNodeItem = (SimpleTreeNode*)item;
>      if (treeNodeItem == nil) {
>         // Since item is nil (the top level), use the root item.
>         treeNodeItem = treeData;
>      }
>      return [treeNodeItem childAtIndex:index];
> }
>
> It probably should be re-written to be easier to understand.
>
> --corbin
>
 _______________________________________________
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

  • Follow-Ups:
    • Re: DragNDropOutlineView Example Define Syntax
      • From: Corbin Dunn <email@hidden>
References: 
 >DragNDropOutlineView Example Define Syntax (From: Ronnie O <email@hidden>)
 >Re: DragNDropOutlineView Example Define Syntax (From: Corbin Dunn <email@hidden>)

  • Prev by Date: Re: "No Selection" in Core Data
  • Next by Date: Re: Correct way to implement validateValue:?
  • Previous by thread: Re: DragNDropOutlineView Example Define Syntax
  • Next by thread: Re: DragNDropOutlineView Example Define Syntax
  • Index(es):
    • Date
    • Thread