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

# NSTableViewDataSource

A set of methods that a table view uses to provide data to a table view and to allow the editing of the table view’s data source object.

```
protocol NSTableViewDataSource : NSObjectProtocol
```

## Overview

Some of the methods in this protocol, such as [`tableView(_:objectValueFor:row:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:objectValueFor:row:)) and [`numberOfRows(in:)`](/documentation/AppKit/NSTableViewDataSource/numberOfRows(in:)) along with other methods that return data, are called frequently, so they must be efficient.

> Note:
> View-based table views must not use the ``doc://com.apple.appkit/documentation/AppKit/NSTableViewDataSource/tableView(_:setObjectValue:for:row:)`` method for setting values. Instead the views must explicitly set the values for the fields, or use Cocoa bindings. Likewise, use target/action for editing. For more information, see ``doc://com.apple.appkit/documentation/AppKit/NSTableView``.

If you’re not using Cocoa bindings to provide data to the table view, the following methods are required:

- [`numberOfRows(in:)`](/documentation/AppKit/NSTableViewDataSource/numberOfRows(in:))
- [`tableView(_:objectValueFor:row:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:objectValueFor:row:))
- [`tableView(_:setObjectValue:for:row:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:setObjectValue:for:row:)) (cell-based tables only)

For more information, see [Cocoa Bindings](/documentation/AppKit/cocoa-bindings).

## Topics

### Getting Values

[`numberOfRows(in:)`](/documentation/AppKit/NSTableViewDataSource/numberOfRows(in:))

Returns the number of records managed for `aTableView` by the data source object.

[`tableView(_:objectValueFor:row:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:objectValueFor:row:))

Called by the table view to return the data object associated with the specified row and column.

### Setting Values

[`tableView(_:setObjectValue:for:row:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:setObjectValue:for:row:))

Sets the data object for an item in the specified row and column.

### Implementing Pasteboard Support

[`tableView(_:pasteboardWriterForRow:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:pasteboardWriterForRow:))

Called to allow the table to support multiple item dragging.

### Drag and Drop

[Supporting Table View Drag and Drop Through File Promises](/documentation/AppKit/supporting-table-view-drag-and-drop-through-file-promises)

Share data between macOS apps during drag and drop by using an item provider.

[`tableView(_:acceptDrop:row:dropOperation:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:acceptDrop:row:dropOperation:))

Called by `aTableView` when the mouse button is released over a table view that previously decided to allow a drop.

[`tableView(_:namesOfPromisedFilesDroppedAtDestination:forDraggedRowsWith:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:namesOfPromisedFilesDroppedAtDestination:forDraggedRowsWith:))

Returns an array of filenames that represent the `indexSet` rows for a drag to `dropDestination`.

[`tableView(_:validateDrop:proposedRow:proposedDropOperation:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:validateDrop:proposedRow:proposedDropOperation:))

Used by `aTableView` to determine a valid drop target.

[`tableView(_:writeRowsWith:to:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:writeRowsWith:to:))

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

[`tableView(_:draggingSession:willBeginAt:forRowIndexes:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:draggingSession:willBeginAt:forRowIndexes:))

Implement this method to determine when a dragging session will begin.

[`tableView(_:updateDraggingItemsForDrag:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:updateDraggingItemsForDrag:))

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

[`tableView(_:draggingSession:endedAt:operation:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:draggingSession:endedAt:operation:))

Implement this method to determine when a dragging session has ended.

### Sorting

[`tableView(_:sortDescriptorsDidChange:)`](/documentation/AppKit/NSTableViewDataSource/tableView(_:sortDescriptorsDidChange:))

Called by `aTableView` to indicate that sorting may need to be done.



---

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)