NSTreeNode Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.5 and later.
Companion guide
Declared in
NSTreeNode.h
Related sample code

Overview

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.

Tasks

Creating Tree Nodes

Getting Information About a Node

Sorting the Subtree

Class Methods

treeNodeWithRepresentedObject:

Creates and returns a tree node that represents the specified object.

+ (id)treeNodeWithRepresentedObject:(id)modelObject
Parameters
modelObject

The object the tree node represents.

Return Value

An initialized tree node that represents modelObject.

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSTreeNode.h

Instance Methods

childNodes

Returns an array containing receiver’s child nodes.

- (NSArray *)childNodes
Return Value

An array containing the receiver’s child nodes.

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSTreeNode.h

descendantNodeAtIndexPath:

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

- (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.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSTreeNode.h

indexPath

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

- (NSIndexPath *)indexPath
Return Value

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

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSTreeNode.h

initWithRepresentedObject:

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

- (id)initWithRepresentedObject:(id)modelObject
Parameters
modelObject

The object the tree node represents.

Return Value

An initialized tree node that represents modelObject.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSTreeNode.h

isLeaf

Returns whether the receiver is a leaf node.

- (BOOL)isLeaf
Return Value

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

Availability
  • Available in OS X v10.5 and later.
Declared In
NSTreeNode.h

mutableChildNodes

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

- (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.

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSTreeNode.h

parentNode

Returns the receiver’s parent node.

- (NSTreeNode *)parentNode
Return Value

The receiver’s parent node.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSTreeNode.h

representedObject

Returns the object the tree node represents.

- (id)representedObject
Return Value

The object the tree node represents.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSTreeNode.h

sortWithSortDescriptors:recursively:

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

- (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.

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSTreeNode.h