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

# NSObjectController

A controller that can manage an object’s properties referenced by key-value paths.

```
class NSObjectController
```

## Overview

[`NSObjectController`](/documentation/AppKit/NSObjectController) is a Cocoa bindings–compatible controller class. Properties of the content object of instances of this class can be bound to user interface elements to access and modify their values.

By default, the content of an [`NSObjectController`](/documentation/AppKit/NSObjectController) instance is an <doc://com.apple.documentation/documentation/Foundation/NSMutableDictionary> object. This allows a single [`NSObjectController`](/documentation/AppKit/NSObjectController) instance to be used to manage many different properties referenced by key-value paths. The default content object class can be changed by calling [`objectClass`](/documentation/AppKit/NSObjectController/objectClass), which subclasses must override. Your application should use a custom data class that is key-value compliant whenever possible.

### Object Controllers, Entity Mode, and Lazy Fetching

`NSObjectController` and its subclasses, when in entity mode, can now fetch lazily. With lazy fetching enabled using the property [`usesLazyFetching`](/documentation/AppKit/NSObjectController/usesLazyFetching), the controller will try to fetch only a small amount of data from available persistent stores. This can provide a significant improvement in memory use when a large amount of content is stored on disk but just a subset of that data is required in memory.

When set to use lazy fetching, a controller will fetch objects in batches. You can change the default batch size for your application by setting a value for the the user default “`com.apple.CocoaBindings.LazyFetchBatchSize`”. If you have table views bound to an array controller set to use lazy fetching, the size of the controller’s batch size will grow as the table views’ visible row count grows.

Add, Insert, and Remove operations on controllers that use lazy fetching behave similarly to the same operations on a regular controller. The difference is that it is faster to sort an array controller using lazy fetching if:

- All of the keys in the `sortDescriptors` array are modeled, non transient properties.
- All of the selectors in the `sortDescriptors` array are `compare:` or `caseInsensitiveCompare:`.
- There are no changes in the controller’s managed object context

## Topics

### Initializing an object controller

[`init(content:)`](/documentation/AppKit/NSObjectController/init(content:))

Initializes and returns an `NSObjectController` object with the given content.

### Managing content

[`content`](/documentation/AppKit/NSObjectController/content)

The receiver’s content object.

[`automaticallyPreparesContent`](/documentation/AppKit/NSObjectController/automaticallyPreparesContent)

A Boolean that shows whether the receiver automatically creates and inserts new content objects automatically when loading from a nib file.

[`prepareContent()`](/documentation/AppKit/NSObjectController/prepareContent())

Typically overridden by subclasses that require additional control over the creation of new objects.

### Setting the content class

[`objectClass`](/documentation/AppKit/NSObjectController/objectClass)

The object class to use when creating new objects.

### Managing objects

[`newObject()`](/documentation/AppKit/NSObjectController/newObject())

Creates and returns a new object of the appropriate class.

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

Sets the receiver’s content object.

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

Removes a given object from the receiver’s content.

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

Creates a new object and sets it as the receiver’s content object.

[`canAdd`](/documentation/AppKit/NSObjectController/canAdd)

A Boolean value that indicates whether an object can be added to the receiver using [`add(_:)`](/documentation/AppKit/NSObjectController/add(_:)).

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

Removes the receiver’s content object.

[`canRemove`](/documentation/AppKit/NSObjectController/canRemove)

A Boolean value that indicates whether an object can be removed from the receiver.

### Managing editing

[`isEditable`](/documentation/AppKit/NSObjectController/isEditable)

A Boolean that indicates whether the receiver allows adding and removing objects.

### Core Data support

[`entityName`](/documentation/AppKit/NSObjectController/entityName)

The entity name used by the receiver to create new objects.

[`fetch(_:)`](/documentation/AppKit/NSObjectController/fetch(_:))

Causes the receiver to fetch the data objects specified by the entity name and fetch predicate.

[`usesLazyFetching`](/documentation/AppKit/NSObjectController/usesLazyFetching)

A Boolean that indicates whether the receiver uses lazy fetching.

[`defaultFetchRequest()`](/documentation/AppKit/NSObjectController/defaultFetchRequest())

Returns the default fetch request used by the receiver.

[`fetchPredicate`](/documentation/AppKit/NSObjectController/fetchPredicate)

The receiver’s fetch predicate.

[`managedObjectContext`](/documentation/AppKit/NSObjectController/managedObjectContext)

The receiver’s managed object context.

[`fetch(with:merge:)`](/documentation/AppKit/NSObjectController/fetch(with:merge:))

Subclasses should override this method to customize a fetch request, for example to specify fetch limits.

### Obtaining selections

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

An array of all objects to be affected by editing.

[`selection`](/documentation/AppKit/NSObjectController/selection)

A proxy object representing the receiver’s selection.

### Validating user interface items

[`validateUserInterfaceItem(_:)`](/documentation/AppKit/NSObjectController/validateUserInterfaceItem(_:))

Returns whether the receiver can handle the action method for a user interface item.

### Initializers

[`init(coder:)`](/documentation/AppKit/NSObjectController/init(coder:))



---

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)