Re: DragNDropOutlineView Example Define Syntax
Re: DragNDropOutlineView Example Define Syntax
- Subject: Re: DragNDropOutlineView Example Define Syntax
- From: email@hidden
- Date: Sat, 25 Jun 2005 15:44:24 -0700
Thats actually a good question. I know the rare (2) times I used it, it was because the instance was a subclass of yet another subclass and I was tired of the compile warning about not responding to such and such selector.
I'd actually love to know the real answer to this too though.
Mark.
------------------------------------------------------------
(Ronnie O) email@hidden wrote on Sat Jun 25 15:38:27 2005:
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 =3D (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 =3D [[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)))
>=20
> Well, these are macros, which are expanded by the C preprocessor. =20
> Anytime you see NODE(n), it is replaced with ((SimpleTreeNode*)n), =20
> where n is the variable passed into the macro. It just saves some =20
> typing.
>=20
> For example, this line:
>=20
> - (id)outlineView:(NSOutlineView *)olv child:(int)index ofItem:(id)=20
> item {
> return [SAFENODE(item) childAtIndex:index];
> }
>=20
> Could have been (typed in mail):
>=20
> - (id)outlineView:(NSOutlineView *)olv child:(int)index ofItem:(id)=20
> item {
> return [((SimpleTreeNode*)((item)?(item):(treeData))) =20
> childAtIndex:index];
> }
>=20
> But, to understand it better, this is the same logic:
>=20
> - (id)outlineView:(NSOutlineView *)olv child:(int)index ofItem:(id)=20
> item {
> SimpleTreeNode* treeNodeItem =3D (SimpleTreeNode*)item;
> if (treeNodeItem =3D=3D nil) {
> // Since item is nil (the top level), use the root item.
> treeNodeItem =3D treeData;
> }
> return [treeNodeItem childAtIndex:index];
> }
>=20
> It probably should be re-written to be easier to understand.
>=20
> --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
_______________________________________________
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