<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSOutlineView",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSOutlineView"
  },
  "title" : "NSOutlineView"
}
-->

# NSOutlineView

A view that uses a row-and-column format to display hierarchical data like directories and files that can be expanded and collapsed.

```
class NSOutlineView
```

## Overview

Like a table view, an outline view does not store its own data, instead it retrieves data values as needed from a data source to which it has a weak reference (see [Delegates and Data Sources](https://developer.apple.com/library/archive/documentation/General/Conceptual/CocoaEncyclopedia/DelegatesandDataSources/DelegatesandDataSources.html#//apple_ref/doc/uid/TP40010810-CH11)). See [`NSOutlineViewDataSource`](/documentation/AppKit/NSOutlineViewDataSource), which declares the methods that an `NSOutlineView` object uses to access the contents of its data source object.

An outline view has the following features:

- A user can expand and collapse rows, edit values, and resize and rearrange columns.
- Each item in the outline view must be unique. In order for the collapsed state to remain consistent between reloads the item’s pointer must remain the same and the item must maintain <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol/isEqual(_:)> sameness.
- The view gets data from a data source (see [`NSOutlineViewDataSource`](/documentation/AppKit/NSOutlineViewDataSource)).
- The view retrieves only the data that needs to be displayed.

> Important:
> It is possible that your data source methods for populating the outline view may be called before <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/awakeFromNib()> if the data source is specified in Interface Builder. You should defend against this by having the data source’s ``doc://com.apple.appkit/documentation/AppKit/NSOutlineViewDataSource/outlineView(_:numberOfChildrenOfItem:)`` method return `0` for the number of items when the data source has not yet been configured. In <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/awakeFromNib()>, when the data source is initialized you should always call ``doc://com.apple.appkit/documentation/AppKit/NSTableView/reloadData()``.

For more information about using NSOutlineView in your app, see [Navigating Hierarchical Data Using Outline and Split Views](/documentation/AppKit/navigating-hierarchical-data-using-outline-and-split-views).

### Subclassing

Subclassing `NSOutlineView` is not recommended. Customization can be accomplished in your data source class implementation (conforming to [`NSOutlineViewDataSource`](/documentation/AppKit/NSOutlineViewDataSource)) or your delegate class implementation (conforming to [`NSOutlineViewDelegate`](/documentation/AppKit/NSOutlineViewDelegate)).

## Topics

### Accessing the Data Source

[`var dataSource: (any NSOutlineViewDataSource)?`](/documentation/AppKit/NSOutlineView/dataSource)

The object that provides the data displayed by the receiver.

[`var stronglyReferencesItems: Bool`](/documentation/AppKit/NSOutlineView/stronglyReferencesItems)

A Boolean value that indicates whether the outline view retains and releases the objects returned from its data source.

### Working with Expandability

[`func isExpandable(Any?) -> Bool`](/documentation/AppKit/NSOutlineView/isExpandable(_:))

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

[`func isItemExpanded(Any?) -> Bool`](/documentation/AppKit/NSOutlineView/isItemExpanded(_:))

Returns a Boolean value that indicates whether a given item is expanded.

### Expanding and Collapsing the Outline

[`func expandItem(Any?)`](/documentation/AppKit/NSOutlineView/expandItem(_:))

Expands a given item.

[`func expandItem(Any?, expandChildren: Bool)`](/documentation/AppKit/NSOutlineView/expandItem(_:expandChildren:))

Expands a specified item and, optionally, its children.

[`func collapseItem(Any?)`](/documentation/AppKit/NSOutlineView/collapseItem(_:))

Collapses a given item.

[`func collapseItem(Any?, collapseChildren: Bool)`](/documentation/AppKit/NSOutlineView/collapseItem(_:collapseChildren:))

Collapses a given item and, optionally, its children.

### Redisplaying Information

[`func reloadItem(Any?)`](/documentation/AppKit/NSOutlineView/reloadItem(_:))

Reloads and redisplays the data for the given item.

[`func reloadItem(Any?, reloadChildren: Bool)`](/documentation/AppKit/NSOutlineView/reloadItem(_:reloadChildren:))

Reloads a given item and, optionally, its children.

### Converting Between Items and Rows

[`func item(atRow: Int) -> Any?`](/documentation/AppKit/NSOutlineView/item(atRow:))

Returns the item associated with a given row.

[`func row(forItem: Any?) -> Int`](/documentation/AppKit/NSOutlineView/row(forItem:))

Returns the row associated with a given item.

### Working with the Outline Column

[`var outlineTableColumn: NSTableColumn?`](/documentation/AppKit/NSOutlineView/outlineTableColumn)

The table column in which hierarchical data is displayed.

[`var autoresizesOutlineColumn: Bool`](/documentation/AppKit/NSOutlineView/autoresizesOutlineColumn)

A Boolean value that indicates whether the outline view resizes its outline column when the user expands or collapses items.

### Working with Indentation

[`func level(forItem: Any?) -> Int`](/documentation/AppKit/NSOutlineView/level(forItem:))

Returns the indentation level for a given item.

[`func level(forRow: Int) -> Int`](/documentation/AppKit/NSOutlineView/level(forRow:))

Returns the indentation level for a given row.

[`var indentationPerLevel: CGFloat`](/documentation/AppKit/NSOutlineView/indentationPerLevel)

The per-level indentation, measured in points.

[`var indentationMarkerFollowsCell: Bool`](/documentation/AppKit/NSOutlineView/indentationMarkerFollowsCell)

A Boolean value indicating whether the indentation marker symbol displayed in the outline column should be indented along with the cell contents.

### Working with Persistence

[`var autosaveExpandedItems: Bool`](/documentation/AppKit/NSOutlineView/autosaveExpandedItems)

A Boolean value indicating whether the expanded items are automatically saved across launches of the app.

### Supporting Drag and Drop

[`func setDropItem(Any?, dropChildIndex: Int)`](/documentation/AppKit/NSOutlineView/setDropItem(_:dropChildIndex:))

Used to “retarget” a proposed drop.

[`func shouldCollapseAutoExpandedItems(forDeposited: Bool) -> Bool`](/documentation/AppKit/NSOutlineView/shouldCollapseAutoExpandedItems(forDeposited:))

Returns a Boolean value that indicates whether auto-expanded items should return to their original collapsed state.

### Getting Related Items

[`func parent(forItem: Any?) -> Any?`](/documentation/AppKit/NSOutlineView/parent(forItem:))

Returns the parent for a given item.

[`func childIndex(forItem: Any) -> Int`](/documentation/AppKit/NSOutlineView/childIndex(forItem:))

Returns the child index of the specified item within its parent.

[`func child(Int, ofItem: Any?) -> Any?`](/documentation/AppKit/NSOutlineView/child(_:ofItem:))

Returns the specified child of an item.

[`func numberOfChildren(ofItem: Any?) -> Int`](/documentation/AppKit/NSOutlineView/numberOfChildren(ofItem:))

Returns the number of children for the specified parent item.

### Getting the Frame for a Cell

[`func frameOfOutlineCell(atRow: Int) -> NSRect`](/documentation/AppKit/NSOutlineView/frameOfOutlineCell(atRow:))

Returns the frame of the outline cell for a given row.

### Accessing the Delegate

[`var delegate: (any NSOutlineViewDelegate)?`](/documentation/AppKit/NSOutlineView/delegate)

The outline view’s delegate.

### Manipulating Items

[`func insertItems(at: IndexSet, inParent: Any?, withAnimation: NSTableView.AnimationOptions)`](/documentation/AppKit/NSOutlineView/insertItems(at:inParent:withAnimation:))

Inserts new items at the given indexes in the given parent with the specified optional animations.

[`func moveItem(at: Int, inParent: Any?, to: Int, inParent: Any?)`](/documentation/AppKit/NSOutlineView/moveItem(at:inParent:to:inParent:))

Moves an item at a given index in the given parent to a new index in a new parent.

[`func removeItems(at: IndexSet, inParent: Any?, withAnimation: NSTableView.AnimationOptions)`](/documentation/AppKit/NSOutlineView/removeItems(at:inParent:withAnimation:))

Removes items at the given indexes in the given parent with the specified optional animations.

### User Interface Layout Direction

[`var userInterfaceLayoutDirection: NSUserInterfaceLayoutDirection`](/documentation/AppKit/NSOutlineView/userInterfaceLayoutDirection)

The user interface layout direction.

### Constants

[Drop on Item Index](/documentation/AppKit/drop-on-item-index)

This constant defines an index that allows you to drop an item directly on a target.

[Outline View Button Keys](/documentation/AppKit/outline-view-button-keys)

These keys are used by the outline view to create disclosure buttons that collapse and expand items.

### Notifications

[`class let columnDidMoveNotification: NSNotification.Name`](/documentation/AppKit/NSOutlineView/columnDidMoveNotification)

Posted whenever a column is moved by user action in an `NSOutlineView` object.

[`class let columnDidResizeNotification: NSNotification.Name`](/documentation/AppKit/NSOutlineView/columnDidResizeNotification)

Posted whenever a column is resized in an `NSOutlineView` object.

[`class let itemDidCollapseNotification: NSNotification.Name`](/documentation/AppKit/NSOutlineView/itemDidCollapseNotification)

Posted whenever an item is collapsed in an `NSOutlineView` object.

[`class let itemDidExpandNotification: NSNotification.Name`](/documentation/AppKit/NSOutlineView/itemDidExpandNotification)

Posted whenever an item is expanded in an `NSOutlineView` object.

[`class let itemWillCollapseNotification: NSNotification.Name`](/documentation/AppKit/NSOutlineView/itemWillCollapseNotification)

Posted before an item is collapsed (after the user clicks the arrow but before the item is collapsed).

[`class let itemWillExpandNotification: NSNotification.Name`](/documentation/AppKit/NSOutlineView/itemWillExpandNotification)

Posted before an item is expanded (after the user clicks the arrow but before the item is collapsed).

[`class let selectionDidChangeNotification: NSNotification.Name`](/documentation/AppKit/NSOutlineView/selectionDidChangeNotification)

Posted after the outline view’s selection changes.

[`class let selectionIsChangingNotification: NSNotification.Name`](/documentation/AppKit/NSOutlineView/selectionIsChangingNotification)

Posted as the outline view’s selection changes (while the mouse button is still down).

### Structures

[`struct ColumnDidMoveMessage`](/documentation/AppKit/NSOutlineView/ColumnDidMoveMessage)

[`struct ColumnDidResizeMessage`](/documentation/AppKit/NSOutlineView/ColumnDidResizeMessage)

[`struct ItemDidCollapseMessage`](/documentation/AppKit/NSOutlineView/ItemDidCollapseMessage)

[`struct ItemDidExpandMessage`](/documentation/AppKit/NSOutlineView/ItemDidExpandMessage)

[`struct ItemWillCollapseMessage`](/documentation/AppKit/NSOutlineView/ItemWillCollapseMessage)

[`struct ItemWillExpandMessage`](/documentation/AppKit/NSOutlineView/ItemWillExpandMessage)

[`struct SelectionDidChangeMessage`](/documentation/AppKit/NSOutlineView/SelectionDidChangeMessage)

[`struct SelectionIsChangingMessage`](/documentation/AppKit/NSOutlineView/SelectionIsChangingMessage)

## Relationships

### Conforms To

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSAccessibilityTable`](/documentation/AppKit/NSAccessibilityTable)

[`NSTextViewDelegate`](/documentation/AppKit/NSTextViewDelegate)

[`Hashable`](/documentation/Swift/Hashable)

[`NSAccessibilityProtocol`](/documentation/AppKit/NSAccessibilityProtocol)

[`NSAppearanceCustomization`](/documentation/AppKit/NSAppearanceCustomization)

[`NSUserInterfaceValidations`](/documentation/AppKit/NSUserInterfaceValidations)

[`Equatable`](/documentation/Swift/Equatable)

[`NSAccessibilityGroup`](/documentation/AppKit/NSAccessibilityGroup)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSStandardKeyBindingResponding`](/documentation/AppKit/NSStandardKeyBindingResponding)

[`Sendable`](/documentation/Swift/Sendable)

[`NSAnimatablePropertyContainer`](/documentation/AppKit/NSAnimatablePropertyContainer)

[`NSAccessibilityOutline`](/documentation/AppKit/NSAccessibilityOutline)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSDraggingDestination`](/documentation/AppKit/NSDraggingDestination)

[`NSUserActivityRestoring`](/documentation/AppKit/NSUserActivityRestoring)

[`NSDraggingSource`](/documentation/AppKit/NSDraggingSource)

[`NSTextDelegate`](/documentation/AppKit/NSTextDelegate)

[`NSTouchBarProvider`](/documentation/AppKit/NSTouchBarProvider)

[`NSAccessibilityElementProtocol`](/documentation/AppKit/NSAccessibilityElementProtocol)

[`NSUserInterfaceItemIdentification`](/documentation/AppKit/NSUserInterfaceItemIdentification)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

### Inherits From

[`NSTableView`](/documentation/AppKit/NSTableView)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)