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

# NSArrayController

A bindings-compatible controller that manages a collection of objects.

```
class NSArrayController
```

## Overview

Typically the collection that an [`NSArrayController`](/documentation/AppKit/NSArrayController) manages is an array, however, if the controller manages a relationship of a managed object (see <doc://com.apple.documentation/documentation/CoreData/NSManagedObject>) the collection may be a set. [`NSArrayController`](/documentation/AppKit/NSArrayController) provides selection management and sorting capabilities.

## Topics

### Managing Sort Descriptors

[`sortDescriptors`](/documentation/AppKit/NSArrayController/sortDescriptors)

An array of sort descriptor objects, used by the receiver to arrange its content.

### Arranging Objects

[`arrange(_:)`](/documentation/AppKit/NSArrayController/arrange(_:))

Returns a given array, appropriately sorted and filtered.

[`arrangedObjects`](/documentation/AppKit/NSArrayController/arrangedObjects)

An array containing the receiver’s content objects arranged using [`arrange(_:)`](/documentation/AppKit/NSArrayController/arrange(_:)).

[`rearrangeObjects()`](/documentation/AppKit/NSArrayController/rearrangeObjects())

Triggers filtering of the receiver’s content.

### Managing Content

[`add(_:)`](/documentation/AppKit/NSArrayController/add(_:))

Creates and adds a new object to the receiver’s content and arranged objects.

### Selection Attributes

[`avoidsEmptySelection`](/documentation/AppKit/NSArrayController/avoidsEmptySelection)

A Boolean value that indicates whether the receiver requires that the content array attempt to maintain a selection

[`preservesSelection`](/documentation/AppKit/NSArrayController/preservesSelection)

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

[`alwaysUsesMultipleValuesMarker`](/documentation/AppKit/NSArrayController/alwaysUsesMultipleValuesMarker)

A Boolean value that indicates whether the receiver always returns the multiple values marker when multiple objects are selected

### Managing selections

[`selectionIndex`](/documentation/AppKit/NSArrayController/selectionIndex)

The index of the first object in the receiver’s selection

[`setSelectionIndex(_:)`](/documentation/AppKit/NSArrayController/setSelectionIndex(_:))

Sets the receiver’s selection to the given index, and returns a Boolean value that indicates whether the selection was changed.

[`selectsInsertedObjects`](/documentation/AppKit/NSArrayController/selectsInsertedObjects)

A Boolean value that indicates whether the receiver automatically selects inserted objects

[`setSelectionIndexes(_:)`](/documentation/AppKit/NSArrayController/setSelectionIndexes(_:))

Sets the receiver’s selection indexes and returns a Boolean value that indicates whether the selection changed.

[`selectionIndexes`](/documentation/AppKit/NSArrayController/selectionIndexes)

An index set containing the indexes of the receiver’s currently selected objects in the content array

[`addSelectionIndexes(_:)`](/documentation/AppKit/NSArrayController/addSelectionIndexes(_:))

Adds the objects at the specified indexes in the receiver’s content array to the current selection.

[`removeSelectionIndexes(_:)`](/documentation/AppKit/NSArrayController/removeSelectionIndexes(_:))

Removes the object as the specified indexes from the receiver’s current selection.

[`setSelectedObjects(_:)`](/documentation/AppKit/NSArrayController/setSelectedObjects(_:))

Sets the specified objects as the receiver’s current selection.

[`selectedObjects`](/documentation/AppKit/NSArrayController/selectedObjects)

An array containing the receiver’s selected objects

[`addSelectedObjects(_:)`](/documentation/AppKit/NSArrayController/addSelectedObjects(_:))

Adds the specified objects from the receiver’s content array to the current selection.

[`removeSelectedObjects(_:)`](/documentation/AppKit/NSArrayController/removeSelectedObjects(_:))

Removes the specified objects from the receiver’s current selection.

[`selectNext(_:)`](/documentation/AppKit/NSArrayController/selectNext(_:))

Selects the next object, relative to the current selection, in the receiver’s arranged content.

[`canSelectNext`](/documentation/AppKit/NSArrayController/canSelectNext)

A Boolean value indicating whether the next object, relative to the current selection, in the receiver’s content array can be selected

[`selectPrevious(_:)`](/documentation/AppKit/NSArrayController/selectPrevious(_:))

Selects the previous object, relative to the current selection, in the receiver’s arranged content.

[`canSelectPrevious`](/documentation/AppKit/NSArrayController/canSelectPrevious)

A Boolean value indicating whether the previous object, relative to the current selection, in the receiver’s content array can be selected

### Inserting

[`canInsert`](/documentation/AppKit/NSArrayController/canInsert)

Returns a Boolean value that indicates whether an object can be inserted into the receiver’s content collection.

[`insert(_:)`](/documentation/AppKit/NSArrayController/insert(_:))

Creates a new object and inserts it into the receiver’s content array.

### Adding and Removing Objects

[`addObject(_:)`](/documentation/AppKit/NSArrayController/addObject(_:))

Adds `object` to the receiver’s content collection and the arranged objects array.

[`add(contentsOf:)`](/documentation/AppKit/NSArrayController/add(contentsOf:))

Adds `objects` to the receiver’s content collection.

[`insert(_:atArrangedObjectIndex:)`](/documentation/AppKit/NSArrayController/insert(_:atArrangedObjectIndex:))

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

[`insert(contentsOf:atArrangedObjectIndexes:)`](/documentation/AppKit/NSArrayController/insert(contentsOf:atArrangedObjectIndexes:))

Inserts `object`s into the receiver’s arranged objects array at the locations specified in `indexes`, and adds it to the receiver’s content collection.

[`remove(atArrangedObjectIndex:)`](/documentation/AppKit/NSArrayController/remove(atArrangedObjectIndex:))

Removes the object at the specified `index` in the receiver’s arranged objects from the receiver’s content array.

[`remove(atArrangedObjectIndexes:)`](/documentation/AppKit/NSArrayController/remove(atArrangedObjectIndexes:))

Removes the objects at the specified `indexes` in the receiver’s arranged objects from the content array.

[`remove(_:)`](/documentation/AppKit/NSArrayController/remove(_:))

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

[`removeObject(_:)`](/documentation/AppKit/NSArrayController/removeObject(_:))

Removes `object` from the receiver’s content collection.

[`remove(contentsOf:)`](/documentation/AppKit/NSArrayController/remove(contentsOf:))

Removes `objects` from the receiver’s content collection.

### Filtering Content

[`clearsFilterPredicateOnInsertion`](/documentation/AppKit/NSArrayController/clearsFilterPredicateOnInsertion)

A Boolean value that indicates whether the receiver automatically clears an existing filter predicate when new items are inserted or added to the content

[`filterPredicate`](/documentation/AppKit/NSArrayController/filterPredicate)

A predicate used by the receiver to filter the array controller contents

### Automatic Content Rearranging

[`automaticallyRearrangesObjects`](/documentation/AppKit/NSArrayController/automaticallyRearrangesObjects)

A Boolean that indicates if the receiver automatically rearranges its content to correspond to the current sort descriptors and filter predicates

[`automaticRearrangementKeyPaths`](/documentation/AppKit/NSArrayController/automaticRearrangementKeyPaths)

An array of key paths that trigger automatic content sorting or filtering

[`didChangeArrangementCriteria()`](/documentation/AppKit/NSArrayController/didChangeArrangementCriteria())

Invoked when any criteria for arranging objects change.



---

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)