• 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: Fri, 24 Jun 2005 09:28:36 -0700

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

  • Prev by Date: Re: Getting an NSImage from an NSTextView
  • Next by Date: Re: What type of window for this?
  • Previous by thread: DragNDropOutlineView Example Define Syntax
  • Next by thread: Re: DragNDropOutlineView Example Define Syntax
  • Index(es):
    • Date
    • Thread