objective-c operator ?:

Discussion in 'Mac Programming' started by medasmx, May 12, 2009.

  1. medasmx macrumors member

    Joined:
    Nov 9, 2008
    #1
    In an apple developer example(DragNDropOutlineView), the following line of code is present --
    "SimpleTreeNode*=(item==nil)?treeData:item;"

    I haven't been able to find documentation regarding this online. However, in the Kochan book, a?b:c is called a conditional(if...then, I suppose). It would read if a is true then b otherwise c. From the above statement to me that means, if item==nil then treeData otherwise item. The full block of code is ...

    Code:
    - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
        SimpleTreeNode *node = (item == nil) ? treeData : item;
        return [node numberOfChildren];
    
    Thanks for any explanation. Adam
     
  2. SilentPanda Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #2
  3. medasmx thread starter macrumors member

    Joined:
    Nov 9, 2008

Share This Page