<!--
{
  "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/entity(forEntityName:in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSEntityDescription(cm)entityForName:inManagedObjectContext:"
  },
  "title" : "entity(forEntityName:in:)"
}
-->

# 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.

```
class func entity(forEntityName entityName: String, in context: NSManagedObjectContext) -> NSEntityDescription?
```

## Parameters

`entityName`

The name of an entity.

`context`

The managed object context to use. Must not be `nil`.

## Return Value

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

## Discussion

Raises <doc://com.apple.documentation/documentation/Foundation/NSExceptionName/internalInconsistencyException> if `context` is `nil`.

This method is functionally equivalent to the following code example.

```objc
NSManagedObjectModel *managedObjectModel = [[context persistentStoreCoordinator] managedObjectModel];
NSEntityDescription *entity = [[managedObjectModel entitiesByName] objectForKey:entityName];
return entity;
```

## See Also

[`entitiesByName`](/documentation/CoreData/NSManagedObjectModel/entitiesByName)

The entities of the model, keyed by name.



---

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)