Class

NSTree​Controller

The NSTree​Controller is a bindings compatible controller that manages a tree of objects. It provides selection and sort management. Its primary purpose is to act as the controller when binding NSOutline​View and NSBrowser instances to a hierarchical collection of objects. The root content object of the tree can be a single object, or an array of objects.

Overview

An NSTree​Controller object requires that you describe how the tree of objects is traversed by specifying the key-path for child objects specified by children​Key​Path. All child objects for the tree must be key-value coding compliant for the same child key path. If necessary, you should add properties to your model classes that map the child key name to the appropriate class-specific property name.

Child objects can implement a count method (specified to the tree controller using count​Key​Path) that, if provided, returns the number of child objects available. Your model objects are expected to update the value of the count key path in a key-value observing compliant method. Optionally, you can also provide a leaf key path using leaf​Key​Path that specifies a key in your model object that returns true if the object is a leaf node, and false if it is not. Changes to the leaf node value of the child object should be made in a key-value observing compliant manner. Providing the leaf node key path can improve performance, because it prevents the NSTree​Controller from having to examine the child object to determine if it is a leaf node.

Symbols

Managing Sort Descriptors

var sort​Descriptors:​ [NSSort​Descriptor]

An array containing the sort descriptors used to arrange the tree controller’s content.

Setting the content

var content:​ Any?

The tree controller’s content object.

Arranging Objects

var arranged​Objects:​ Any

The tree controller’s sorted content objects.

func rearrange​Objects()

Use this method to trigger reordering of the tree controller’s content.

Getting the current selection

func set​Selection​Index​Path(Index​Path?)

Sets the tree controller’s current selection.

var selection​Index​Path:​ Index​Path?

The index path of the first selected object.

func set​Selection​Index​Paths([Index​Path])

Sets the tree controller’s current selection to the specified index paths.

var selection​Index​Paths:​ [Index​Path]

An array containing the index paths of the currently selected objects.

var selected​Objects:​ [Any]

An array containing the currently selected objects in the tree controller’s content.

var selected​Nodes:​ [NSTree​Node]

An array containing the tree controller’s selected tree nodes.

Managing Selections

var selects​Inserted​Objects:​ Bool

A Boolean value that indicates whether the tree controller automatically selects objects as they are inserted.

func add​Selection​Index​Paths([Index​Path])

Adds the objects at the specified index​Paths in the tree controller’s content to the current selection.

func remove​Selection​Index​Paths([Index​Path])

Removes the objects at the specified index​Paths from the tree controller’s current selection, returning true if the selection was changed.

var avoids​Empty​Selection:​ Bool

A Boolean value that indicates whether the tree controller requires the content array to attempt to maintain a selection at all times, avoiding an empty selection.

var preserves​Selection:​ Bool

A Boolean value that indicates whether the tree controller will attempt to preserve the current selection when the content changes.

var always​Uses​Multiple​Values​Marker:​ Bool

A Boolean value that indicates whether the tree controller always returns the multiple values marker when multiple objects are selected, even if the selected items have the same value.

Adding, inserting and removing objects

func add(Any?)

Adds an object to the tree controller’s content after the current selection.

func add​Child(Any?)

Adds a child object to the currently selected item.

var can​Add​Child:​ Bool

A Boolean value that indicates if a child object can be added to the tree controller’s content.

var can​Insert:​ Bool

A Boolean value that indicates if an object can be inserted into the tree controller’s content.

var can​Insert​Child:​ Bool

A Boolean value that indicates if a child object can be inserted into the tree controller’s content.

func insert(Any?)

Creates a new object of the class specified by object​Class and inserts it into the tree controller’s content.

func insert​Child(Any?)

Creates a new object of the class specified by object​Class and inserts it into the tree controller’s content as a child of the current selection.

func insert(Any?, at​Arranged​Object​Index​Path:​ Index​Path)

Inserts object into the tree controller’s arranged objects array at the location specified by index​Path, and adds it to the tree controller’s content.

func insert([Any], at​Arranged​Object​Index​Paths:​ [Index​Path])

Inserts objects into the tree controller’s arranged objects array at the locations specified in index​Paths, and adds them to the tree controller’s content.

func remove(Any?)

Removes the tree controller’s selected objects from the content.

func remove​Object(at​Arranged​Object​Index​Path:​ Index​Path)

Removes the object at the specified index​Path in the tree controller’s arranged objects from the tree controller’s content.

func remove​Objects(at​Arranged​Object​Index​Paths:​ [Index​Path])

Removes the objects at the specified index​Paths in the tree controller’s arranged objects from the tree controller’s content.

func move(NSTree​Node, to:​ Index​Path)

Moves the specified tree node to the new index path.

func move([NSTree​Node], to:​ Index​Path)

Moves the specified tree nodes to the new index path.

Specifying model attributes

var children​Key​Path:​ String?

The key path used to find the children in the tree controller’s objects.

func children​Key​Path(for:​ NSTree​Node)

Returns the key path used to find the children in the specified tree node.

var count​Key​Path:​ String?

The key path used to find the number of children for a node.

func count​Key​Path(for:​ NSTree​Node)

Returns the key path that provides the number of children for a specified node.

var leaf​Key​Path:​ String?

The key path used by the tree controller to determine if a node is a leaf key.

func leaf​Key​Path(for:​ NSTree​Node)

Returns the key path that specifies whether the node is a leaf node.

Relationships