<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSEntityDescription",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSEntityDescription"
  },
  "title" : "NSEntityDescription"
}
-->

# NSEntityDescription

A description of a Core Data entity.

```
class NSEntityDescription
```

## Overview

Entities are to managed objects what `Class` is to `id`, or — to use a database analogy — what tables are to rows. An instance specifies the entity’s name, its attributes and relationships (as instances of [`NSAttributeDescription`](/documentation/CoreData/NSAttributeDescription) and [`NSRelationshipDescription`](/documentation/CoreData/NSRelationshipDescription)) and the class that represents it. Instances of that class correspond to entries in the associated persistent store. As a minimum, an entity description requires:

- A name.
- The class name of the corresponding managed object.

If you don’t specify a class name, the framework uses [`NSManagedObject`](/documentation/CoreData/NSManagedObject).

You define entities in a managed object model (an instance of [`NSManagedObjectModel`](/documentation/CoreData/NSManagedObjectModel)) using Xcode’s data modeling tool. Core Data uses `NSEntityDescription` to map entries in the persistent store to managed objects in your app. It’s unlikely you’ll interact with entity descriptions directly unless you’re specifically working with models. `NSEntityDescription` provides a user dictionary for you to store any related, app-specific information.

### Editing entity descriptions

Entity descriptions are editable until an object graph manager uses them, which allows you to create or modify descriptions dynamically. However, once you associate the description’s managed object model with a persistent store coordinator, you can no longer modify it. The framework enforces this rule at runtime; any attempt to mutate the model, or any of its child objects, after you associate it with a persistent store coordinator results in an exception. If you need to modify a model that’s in use, create a copy of that model, modify it, and then discard the stale model.

If you want to create an entity hierarchy, consider the relevant API. You can only set an entity’s [`subentities`](/documentation/CoreData/NSEntityDescription/subentities), not an entity’s super-entity. To set an entity’s super-entity, set an array of subentities on the super entity that includes the desired entity; the entity hierarchy is built top-down.

### Using entity descriptions in dictionaries

The `copy` method of `NSEntityDescription` returns an entity such that:

```objc
[[entity copy] isEqual:entity] == NO
```

Since <doc://com.apple.documentation/documentation/Foundation/NSDictionary> copies its keys and requires that keys both conform to the <doc://com.apple.documentation/documentation/Foundation/NSCopying> protocol and have a property that `copy` returns an object for where the source and the copy are equal, don’t use entities as keys in a dictionary. Instead, use either the entity’s name as the key or use an <doc://com.apple.documentation/documentation/Foundation/NSMapTable> with retain callbacks.

### Fast enumeration

`NSEntityDescription` implements the <doc://com.apple.documentation/documentation/Foundation/NSFastEnumeration> protocol. Use this to enumerate over an entity’s properties, as the following example illustrates.

```objc
NSEntityDescription *anEntity = ...;
for (NSPropertyDescription *property in anEntity) {
    // property is each instance of NSPropertyDescription in anEntity in turn
}
```

## Topics

### Getting descriptive information

[`name`](/documentation/CoreData/NSEntityDescription/name)

The entity name of the receiver.

[`managedObjectModel`](/documentation/CoreData/NSEntityDescription/managedObjectModel)

The managed object model with which the receiver is associated.

[`managedObjectClassName`](/documentation/CoreData/NSEntityDescription/managedObjectClassName)

The name of the class that represents the receiver’s entity.

[`renamingIdentifier`](/documentation/CoreData/NSEntityDescription/renamingIdentifier)

The renaming identifier for the receiver.

[`abstract`](/documentation/CoreData/NSEntityDescription/isAbstract)

A Boolean value that indicates whether the receiver represents an abstract entity.

[`userInfo`](/documentation/CoreData/NSEntityDescription/userInfo)

The user info dictionary of the receiver.

[`coreSpotlightDisplayNameExpression`](/documentation/CoreData/NSEntityDescription/coreSpotlightDisplayNameExpression)

The expression that computes the CoreSpotlight display name for instances of the entity.

### Managing inheritance

[`subentitiesByName`](/documentation/CoreData/NSEntityDescription/subentitiesByName)

A dictionary containing the receiver’s sub-entities.

[`subentities`](/documentation/CoreData/NSEntityDescription/subentities)

An array containing the sub-entities of the receiver.

[`superentity`](/documentation/CoreData/NSEntityDescription/superentity)

The super-entity of the receiver.

[`-  isKindOfEntity:`](/documentation/CoreData/NSEntityDescription/isKindOf(entity:))

Returns a Boolean value that indicates whether the receiver is a sub-entity of another given entity.

### Working with properties

[`propertiesByName`](/documentation/CoreData/NSEntityDescription/propertiesByName)

A dictionary containing the properties of the receiver.

[`properties`](/documentation/CoreData/NSEntityDescription/properties)

An array containing the properties of the receiver.

[`attributesByName`](/documentation/CoreData/NSEntityDescription/attributesByName)

The attributes of the receiver in a dictionary.

[`relationshipsByName`](/documentation/CoreData/NSEntityDescription/relationshipsByName)

The relationships of the receiver in a dictionary.

[`-  relationshipsWithDestinationEntity:`](/documentation/CoreData/NSEntityDescription/relationships(forDestination:))

Returns an array containing the relationships of the receiver where the entity description of the relationship is a given entity.

### Configuring indexes and constraints

[`indexes`](/documentation/CoreData/NSEntityDescription/indexes)

An array of fetch index descriptions for the entity.

[`uniquenessConstraints`](/documentation/CoreData/NSEntityDescription/uniquenessConstraints)

An array of arrays that contains one or more attributes with a value that must be unique over the instances of that entity.

[`compoundIndexes`](/documentation/CoreData/NSEntityDescription/compoundIndexes)

The compound indexes for the entity as an array of arrays.

### Creating a managed object

[`+  insertNewObjectForEntityForName:inManagedObjectContext:`](/documentation/CoreData/NSEntityDescription/insertNewObject(forEntityName:into:))

Creates, configures, and returns an instance of the class for the entity with a given name.

### Retrieving a description by its name

[`+  entityForName:inManagedObjectContext:`](/documentation/CoreData/NSEntityDescription/entity(forEntityName:in:))

Returns the entity with the specified name from the managed object model associated with the specified managed object context’s persistent store coordinator.

### Managing versioning

[`versionHash`](/documentation/CoreData/NSEntityDescription/versionHash)

The version hash for the receiver.

[`versionHashModifier`](/documentation/CoreData/NSEntityDescription/versionHashModifier)

The version hash modifier for the receiver.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

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

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)