Mac Developer Library

Developer

AppKit Framework Reference NSTreeNode Class Reference

Options
Deployment Target:

On This Page
Language:

NSTreeNode

NSTreeNode simplifies the creation and management of trees of objects. Each tree node represents a model object. A tree node with nil as its parent node is considered the root of the tree.

Inheritance


Conforms To


Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.5 and later.
  • Creates and returns a tree node that represents the specified object.

    Declaration

    Objective-C

    + (instancetype)treeNodeWithRepresentedObject:(id)modelObject

    Parameters

    modelObject

    The object the tree node represents.

    Return Value

    An initialized tree node that represents modelObject.

    Import Statement

    Availability

    Available in OS X v10.5 and later.

  • Initializes a newly allocated tree node that represents the specified object.

    Declaration

    Swift

    init(representedObject modelObject: AnyObject!)

    Objective-C

    - (instancetype)initWithRepresentedObject:(id)modelObject

    Parameters

    modelObject

    The object the tree node represents.

    Return Value

    An initialized tree node that represents modelObject.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the object the tree node represents.

    Declaration

    Swift

    var representedObject: AnyObject! { get }

    Objective-C

    @property(readonly, strong) id representedObject

    Return Value

    The object the tree node represents.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the position of the receiver relative to its root parent.

    Declaration

    Swift

    var indexPath: NSIndexPath { get }

    Objective-C

    @property(readonly, strong) NSIndexPath *indexPath

    Return Value

    An index path that represents the receiver’s position relative to the tree’s root node.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • isLeaf isLeaf Available in OS X v10.5 through OS X v10.9

    Returns whether the receiver is a leaf node.

    Declaration

    Objective-C

    - (BOOL)isLeaf

    Return Value

    YEStrue if the receiver is a leaf node (has no child nodes), otherwise NOfalse.

    Import Statement

    Availability

    Available in OS X v10.5 through OS X v10.9.

  • Returns an array containing receiver’s child nodes.

    Declaration

    Swift

    var childNodes: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSArray *childNodes

    Return Value

    An array containing the receiver’s child nodes.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns a mutable array that provides read-write access to the receiver’s child nodes.

    Declaration

    Swift

    var mutableChildNodes: NSMutableArray! { get }

    Objective-C

    @property(readonly, strong) NSMutableArray *mutableChildNodes

    Return Value

    A mutable array that provides read-write access to the receiver’s child nodes.

    Discussion

    Nodes that are inserted into this array have their parent nodes set to the receiver. Nodes that are removed from this array automatically have their parent node set to nil. The array that is returned is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the receiver’s descendent at the specified index path.

    Declaration

    Swift

    func descendantNodeAtIndexPath(_ indexPath: NSIndexPath) -> NSTreeNode?

    Objective-C

    - (NSTreeNode *)descendantNodeAtIndexPath:(NSIndexPath *)indexPath

    Parameters

    indexPath

    An index path specifying a descendent of the receiver.

    Return Value

    A tree node, or nil if the node does not exist.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the receiver’s parent node.

    Declaration

    Swift

    unowned(unsafe) var parentNode: NSTreeNode? { get }

    Objective-C

    @property(readonly, assign) NSTreeNode *parentNode

    Return Value

    The receiver’s parent node.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sorts the receiver’s subtree using the values of the represented objects with the specified sort descriptors.

    Declaration

    Swift

    func sortWithSortDescriptors(_ sortDescriptors: [AnyObject], recursively recursively: Bool)

    Objective-C

    - (void)sortWithSortDescriptors:(NSArray *)sortDescriptors recursively:(BOOL)recursively

    Parameters

    sortDescriptors

    Array of sort descriptors specifying how to sort the represented objects.

    recursively

    A Boolean that specifies whether the child nodes should be sorted recursively.

    Discussion

    All the represented objects in the child nodes must be key-value coding compliant for the keys specified in the sort descriptors.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.