Mac Developer Library

Developer

AppKit Framework Reference NSTreeController Class Reference

Options
Deployment Target:

On This Page
Language:

NSTreeController

The NSTreeController 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 NSOutlineView 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. More...

Inheritance


Conforms To


Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.4 and later.
  • Sets the sort descriptors used to arrange the receiver's contents.

    Declaration

    Swift

    var sortDescriptors: [AnyObject]!

    Objective-C

    @property(copy) NSArray *sortDescriptors

    Parameters

    sortDescriptors

    An array of NSSortDescriptor objects. Passing nil causes the contents to be arranged in their natural order.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns an array containing the sort descriptors used to arrange the receiver's content.

    Declaration

    Swift

    var sortDescriptors: [AnyObject]!

    Objective-C

    @property(copy) NSArray *sortDescriptors

    Return Value

    Returns an array containing the tree controller’s sort descriptors. Returns nil if the receiver has no sort descriptors configured.

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the receiver’s content.

    Declaration

    Swift

    var content: AnyObject!

    Objective-C

    @property(strong) id content

    Parameters

    content

    The content. The content can be an array of objects, or a single root object.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – content

  • Returns the receiver’s content object.

    Declaration

    Swift

    var content: AnyObject!

    Objective-C

    @property(strong) id content

    Return Value

    The receiver’s content object.

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – setContent:

  • Returns the tree controller’s sorted content objects.

    Declaration

    Swift

    var arrangedObjects: AnyObject { get }

    Objective-C

    @property(readonly, strong) id arrangedObjects

    Return Value

    A proxy root tree note containing the receiver’s sorted content objects. The proxy object responds to childNodes and descendantNodeAtIndexPath: messages.

    Discussion

    This property is observable using key-value observing.

    Special Considerations

    Prior to OS X v10.5 this method returned an opaque root node object representing all the currently displayed objects. That return value was only suitable for use with Cocoa bindings, and no assumption should be made about what methods that opaque object supports.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Use this method to trigger reordering of the receiver’s content.

    Declaration

    Swift

    func rearrangeObjects()

    Objective-C

    - (void)rearrangeObjects

    Discussion

    Subclasses should invoke this method if any parameter that affects the arranged objects changes.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the receiver’s current selection.

    Declaration

    Swift

    func setSelectionIndexPath(_ indexPath: NSIndexPath?) -> Bool

    Objective-C

    - (BOOL)setSelectionIndexPath:(NSIndexPath *)indexPath

    Parameters

    indexPath

    The proposed new selection.

    Return Value

    Return YEStrue if the selection has changed, otherwise NOfalse.

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the index path of the first selected object.

    Declaration

    Swift

    @NSCopying var selectionIndexPath: NSIndexPath? { get }

    Objective-C

    @property(readonly, copy) NSIndexPath *selectionIndexPath

    Return Value

    Returns an index path of the first object in the tree controller’s selection. Returns nil if there is no selection.

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the receiver’s current selection to the specified index paths.

    Declaration

    Swift

    func setSelectionIndexPaths(_ indexPaths: [AnyObject]!) -> Bool

    Objective-C

    - (BOOL)setSelectionIndexPaths:(NSArray *)indexPaths

    Parameters

    indexPaths

    An array of NSIndexpath objects specifying the selected objects.

    Return Value

    Return YEStrue if the selection has changed, otherwise NOfalse.

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns an array containing the index paths of the currently selected objects.

    Declaration

    Swift

    var selectionIndexPaths: [AnyObject]! { get }

    Objective-C

    @property(readonly, copy) NSArray *selectionIndexPaths

    Return Value

    An array containing NSIndexPath objects for each of the selected objects in the tree controller’s content.

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns an array containing the currently selected objects.

    Declaration

    Swift

    var selectedObjects: [AnyObject]! { get }

    Objective-C

    @property(readonly, copy) NSArray *selectedObjects

    Return Value

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

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns an array of the receiver’s selected tree nodes.

    Declaration

    Swift

    var selectedNodes: [AnyObject]! { get }

    Objective-C

    @property(readonly, copy) NSArray *selectedNodes

    Return Value

    An array containing the receiver’s selected tree nodes

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sets whether the receiver will automatically select objects as they are inserted.

    Declaration

    Swift

    var selectsInsertedObjects: Bool

    Objective-C

    @property BOOL selectsInsertedObjects

    Discussion

    If flag is YEStrue then items will be selected upon insertion. The default is YEStrue.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns whether the receiver selects inserted objects automatically.

    Declaration

    Swift

    var selectsInsertedObjects: Bool

    Objective-C

    @property BOOL selectsInsertedObjects

    Discussion

    The default is YEStrue.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Adds the objects at the specified indexPaths in the receiver’s content to the current selection.

    Declaration

    Swift

    func addSelectionIndexPaths(_ indexPaths: [AnyObject]) -> Bool

    Objective-C

    - (BOOL)addSelectionIndexPaths:(NSArray *)indexPaths

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Removes the objects at the specified indexPaths from the receiver’s current selection, returning YEStrue if the selection was changed.

    Declaration

    Swift

    func removeSelectionIndexPaths(_ indexPaths: [AnyObject]) -> Bool

    Objective-C

    - (BOOL)removeSelectionIndexPaths:(NSArray *)indexPaths

    Discussion

    Attempting to change the selection may cause a commitEditing message which fails, thus denying the selection change.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets whether the receiver will attempt to avoid an empty selection.

    Declaration

    Swift

    var avoidsEmptySelection: Bool

    Objective-C

    @property BOOL avoidsEmptySelection

    Discussion

    If flag is YEStrue then the receiver will maintain a selection unless there are no objects in the content. The default is YEStrue.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns whether the receiver requires that the content array attempt to maintain a selection at all times.

    Declaration

    Swift

    var avoidsEmptySelection: Bool

    Objective-C

    @property BOOL avoidsEmptySelection

    Discussion

    The default is YEStrue.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets whether the receiver will attempt to preserve selection when the content changes.

    Declaration

    Swift

    var preservesSelection: Bool

    Objective-C

    @property BOOL preservesSelection

    Discussion

    If flag is YEStrue then the selection will be preserved, if possible. The default is YEStrue.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns whether the receiver will attempt to preserve the current selection when the content changes.

    Declaration

    Swift

    var preservesSelection: Bool

    Objective-C

    @property BOOL preservesSelection

    Discussion

    The default is YEStrue.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets whether the receiver always returns the multiple values marker when multiple objects are selected, even if they have the same value.

    Declaration

    Swift

    var alwaysUsesMultipleValuesMarker: Bool

    Objective-C

    @property BOOL alwaysUsesMultipleValuesMarker

    Discussion

    Setting flag to YEStrue can increase performance if your application doesn’t allow editing multiple values. The default is NOfalse.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns whether the receiver always returns the multiple values marker when multiple objects are selected, even if the selected items have the same value.

    Declaration

    Swift

    var alwaysUsesMultipleValuesMarker: Bool

    Objective-C

    @property BOOL alwaysUsesMultipleValuesMarker

    Discussion

    The default is NOfalse.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Adds an object to the receiver after the current selection.

    Declaration

    Swift

    func add(_ sender: AnyObject?)

    Objective-C

    - (void)add:(id)sender

    Discussion

    The sender is typically the object that invoked this method.

    If the receiver is in object mode newObject is called and the returned object is added to the collection. If the receiver is in entity mode a new object is created that is appropriate as specified by the entity, and newObject is not used.

    Special Considerations

    Beginning with OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – remove:

  • Adds a child object to the currently selected item.

    Declaration

    Swift

    func addChild(_ sender: AnyObject?)

    Objective-C

    - (void)addChild:(id)sender

    Discussion

    The sender is typically the object that invoked this method.

    If the receiver is in object mode newObject is called and the returned object is added as a child. If the receiver is in entity mode a new object is created that is appropriate for the relationship as specified by the entity, and newObject is not used.

    Special Considerations

    Beginning with OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – remove:

  • Returns YEStrue if a child object can be added to the receiver’s content.

    Declaration

    Swift

    var canAddChild: Bool { get }

    Objective-C

    @property(readonly) BOOL canAddChild

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns YEStrue if an object can be inserted into the receiver’s content.

    Declaration

    Swift

    var canInsert: Bool { get }

    Objective-C

    @property(readonly) BOOL canInsert

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns YEStrue if a child object can be inserted into the receiver’s content.

    Declaration

    Swift

    var canInsertChild: Bool { get }

    Objective-C

    @property(readonly) BOOL canInsertChild

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Creates a new object of the class specified by objectClass and inserts it into the receiver’s content.

    Declaration

    Swift

    func insert(_ sender: AnyObject?)

    Objective-C

    - (void)insert:(id)sender

    Discussion

    The sender is typically the object that invoked this method.

    If the receiver is in object mode newObject is called and the returned object is inserted into the collection. If the receiver is in entity mode a new object is created that is appropriate as specified by the entity, and newObject is not used.

    Special Considerations

    Beginning with OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – add:

  • Creates a new object of the class specified by objectClass and inserts it into the receiver’s content as a child of the current selection.

    Declaration

    Swift

    func insertChild(_ sender: AnyObject?)

    Objective-C

    - (void)insertChild:(id)sender

    Discussion

    The sender is typically the object that invoked this method.

    If the receiver is in object mode newObject is called and the returned object is inserted as a child. If the receiver is in entity mode a new object is created that is appropriate for the relationship as specified by the entity, and newObject is not used.

    Special Considerations

    Beginning with OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – add:

  • Inserts object into the receiver’s arranged objects array at the location specified by indexPath, and adds it to the receiver’s content.

    Declaration

    Swift

    func insertObject(_ object: AnyObject!, atArrangedObjectIndexPath indexPath: NSIndexPath)

    Objective-C

    - (void)insertObject:(id)object atArrangedObjectIndexPath:(NSIndexPath *)indexPath

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Inserts objects into the receiver’s arranged objects array at the locations specified in indexPaths, and adds them to the receiver’s content.

    Declaration

    Swift

    func insertObjects(_ objects: [AnyObject], atArrangedObjectIndexPaths indexPaths: [AnyObject])

    Objective-C

    - (void)insertObjects:(NSArray *)objects atArrangedObjectIndexPaths:(NSArray *)indexPaths

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Removes the receiver’s selected objects from the content.

    Declaration

    Swift

    func remove(_ sender: AnyObject?)

    Objective-C

    - (void)remove:(id)sender

    Discussion

    The sender is typically the object that invoked this method.

    Special Considerations

    Beginning with OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – add:

  • Removes the object at the specified indexPath in the receiver’s arranged objects from the receiver’s content.

    Declaration

    Swift

    func removeObjectAtArrangedObjectIndexPath(_ indexPath: NSIndexPath)

    Objective-C

    - (void)removeObjectAtArrangedObjectIndexPath:(NSIndexPath *)indexPath

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Removes the objects at the specified indexPaths in the receiver’s arranged objects from the receiver’s content.

    Declaration

    Swift

    func removeObjectsAtArrangedObjectIndexPaths(_ indexPaths: [AnyObject])

    Objective-C

    - (void)removeObjectsAtArrangedObjectIndexPaths:(NSArray *)indexPaths

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Moves the specified tree node to the new index path.

    Declaration

    Swift

    func moveNode(_ node: NSTreeNode, toIndexPath indexPath: NSIndexPath)

    Objective-C

    - (void)moveNode:(NSTreeNode *)node toIndexPath:(NSIndexPath *)indexPath

    Parameters

    node

    A tree node.

    indexPath

    An index path specifying the new position in the receiver’s content.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Moves the specified tree nodes to the new index path.

    Declaration

    Swift

    func moveNodes(_ nodes: [AnyObject], toIndexPath startingIndexPath: NSIndexPath)

    Objective-C

    - (void)moveNodes:(NSArray *)nodes toIndexPath:(NSIndexPath *)startingIndexPath

    Parameters

    nodes

    An array of tree nodes.

    startingIndexPath

    An index path specifying the starting position to move the tree nodes to in the receiver’s content.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sets the key path used by the receiver to access child objects to key.

    Declaration

    Swift

    var childrenKeyPath: String!

    Objective-C

    @property(copy) NSString *childrenKeyPath

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the key path used to find the children in the receiver’s objects.

    Declaration

    Swift

    var childrenKeyPath: String!

    Objective-C

    @property(copy) NSString *childrenKeyPath

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the key path used by the receiver to determine the number of objects at a node to key.

    Declaration

    Swift

    var countKeyPath: String!

    Objective-C

    @property(copy) NSString *countKeyPath

    Discussion

    Specifying this key path, if the data is available in the model object, can increase performance, but disables insert and remove functionality.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

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

    Declaration

    Swift

    func childrenKeyPathForNode(_ node: NSTreeNode) -> String?

    Objective-C

    - (NSString *)childrenKeyPathForNode:(NSTreeNode *)node

    Parameters

    node

    A tree node in the receiver.

    Return Value

    A string containing the key path in node that provides the child nodes.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    var countKeyPath: String!

    Objective-C

    @property(copy) NSString *countKeyPath

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

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

    Declaration

    Swift

    func countKeyPathForNode(_ node: NSTreeNode) -> String?

    Objective-C

    - (NSString *)countKeyPathForNode:(NSTreeNode *)node

    Parameters

    node

    A tree node in the receiver.

    Return Value

    A string containing the key path in node that provides the number of children.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sets the key path used by the receiver to determine if an object is a leaf node to key.

    Declaration

    Swift

    var leafKeyPath: String?

    Objective-C

    @property(copy) NSString *leafKeyPath

    Discussion

    Specifying this key path is optional. If the receiver is able to determine that a node is a leaf node, it can disable inserting or adding children to those nodes.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    See Also

    – leafKeyPath

  • Returns the key path used by the receiver to determine if a node is a leaf key.

    Declaration

    Swift

    var leafKeyPath: String?

    Objective-C

    @property(copy) NSString *leafKeyPath

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

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

    Declaration

    Swift

    func leafKeyPathForNode(_ node: NSTreeNode) -> String?

    Objective-C

    - (NSString *)leafKeyPathForNode:(NSTreeNode *)node

    Parameters

    node

    A tree node in the receiver.

    Return Value

    A string containing the key path in node that specifies that the node is a leaf node.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.