Protocol

NSOutlineViewDataSource

A set of methods that an outline view calls to retrieve data and information about it from the data source delegate, and—optionally—to update data values.

Overview

NSOutlineView objects support a data source delegate in addition to the regular delegate object.

All the methods in the NSOutlineViewDataSource protocol are marked as @optional. While this is true, there are cases were you must implement some methods to achieve required functionality, specifically when working with conventional data sources rather than data that is provided by Cocoa bindings.

Required and Optional Methods Using Programmatic Conventions and Cocoa Bindings

If you are using conventional data sources for content you must implement the basic methods that provide the outline view with data: outlineView(_:child:ofItem:), outlineView(_:isItemExpandable:), outlineView(_:numberOfChildrenOfItem:), and outlineView(_:objectValueFor:byItem:). Applications that acquire their data using Cocoa bindings do not need to implement these methods.

Similarly, when using conventional data sources , if you want to allow the user to edit values, you must implement outlineView(_:setObjectValue:for:byItem:). When these methods are invoked by the outline view, nil as the item refers to the “root” item. NSOutlineView requires that each item in the outline view be unique. In order for the collapsed state of an outline view to remain consistent between reloads you must always return the same object for an item. When using Cocoa bindings to provide outline view content, there is no requirement to implement this method.

Topics

Instance Methods

func outlineView(NSOutlineView, acceptDrop: NSDraggingInfo, item: Any?, childIndex: Int)

Returns a Boolean value that indicates whether a drop operation was successful.

func outlineView(NSOutlineView, child: Int, ofItem: Any?)

Returns the child item at the specified index of a given item.

func outlineView(NSOutlineView, draggingSession: NSDraggingSession, willBeginAt: NSPoint, forItems: [Any])

Implement this method know when the given dragging session is about to begin and potentially modify the dragging session.

func outlineView(NSOutlineView, isItemExpandable: Any)

Returns a Boolean value that indicates whether the a given item is expandable.

func outlineView(NSOutlineView, itemForPersistentObject: Any)

Invoked by outlineView to return the item for the archived object.

func outlineView(NSOutlineView, namesOfPromisedFilesDroppedAtDestination: URL, forDraggedItems: [Any])

Returns an array of filenames for the created files that the receiver promises to create.

Deprecated
func outlineView(NSOutlineView, numberOfChildrenOfItem: Any?)

Returns the number of child items encompassed by a given item.

func outlineView(NSOutlineView, objectValueFor: NSTableColumn?, byItem: Any?)

Invoked by outlineView to return the data object associated with the specified item.

func outlineView(NSOutlineView, pasteboardWriterForItem: Any)

Implement this method to enable the table to be an NSDraggingSource that supports dragging multiple items.

func outlineView(NSOutlineView, persistentObjectForItem: Any?)

Invoked by outlineView to return an archived object for item.

func outlineView(NSOutlineView, sortDescriptorsDidChange: [NSSortDescriptor])

Invoked by an outline view to notify the data source that the descriptors changed and the data may need to be resorted.

func outlineView(NSOutlineView, updateDraggingItemsForDrag: NSDraggingInfo)

Implement this method to enable the table to update dragging items as they are dragged over the view.

func outlineView(NSOutlineView, writeItems: [Any], to: NSPasteboard)

Returns a Boolean value that indicates whether a drag operation is allowed.

Relationships

Inherits From

See Also

Management

protocol NSOutlineViewDelegate

A set of optional methods implemented by delegates of NSOutlineView objects.