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.

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

    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.

    Availability

    Available in OS X v10.5 and later.

  • The object the tree node represents. (read-only)

    Declaration

    Swift

    var representedObject: AnyObject? { get }

    Objective-C

    @property(readonly, strong) id representedObject

    Availability

    Available in OS X v10.5 and later.

  • The position of the receiver relative to its root parent. (read-only)

    Declaration

    Swift

    var indexPath: NSIndexPath { get }

    Objective-C

    @property(readonly, strong) NSIndexPath *indexPath

    Availability

    Available in OS X v10.5 and later.

  • leaf leaf Property

    A Boolean that indicates whether the receiver is a leaf node. (read-only)

    Declaration

    Swift

    var leaf: Bool { get }

    Objective-C

    @property(getter=isLeaf, readonly) BOOL leaf

    Discussion

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

    Availability

    Available in OS X v10.5 and later.

  • An array containing receiver’s child nodes. (read-only)

    Declaration

    Swift

    var childNodes: [NSTreeNode]? { get }

    Objective-C

    @property(readonly, copy) NSArray <NSTreeNode *> *childNodes

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var mutableChildNodes: NSMutableArray { get }

    Objective-C

    @property(readonly, strong) NSMutableArray <NSTreeNode *> *mutableChildNodes

    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.

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

    Availability

    Available in OS X v10.5 and later.

  • The receiver’s parent node. (read-only)

    Declaration

    Swift

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

    Objective-C

    @property(readonly, assign) NSTreeNode *parentNode

    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: [NSSortDescriptor], recursively recursively: Bool)

    Objective-C

    - (void)sortWithSortDescriptors:(NSArray<NSSortDescriptor *> *)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.