---
title: "entity(forEntityName:in:)"
framework: coredata
role: symbol
role_heading: Type Method
path: "coredata/nsentitydescription/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.

## Declaration

```swift
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

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

## Discussion

Discussion Raises internalInconsistencyException if context is nil. This method is functionally equivalent to the following code example. NSManagedObjectModel *managedObjectModel = [[context persistentStoreCoordinator] managedObjectModel]; NSEntityDescription *entity = [[managedObjectModel entitiesByName] objectForKey:entityName]; return entity;

## See Also

### Related Documentation

- [entitiesByName](coredata/nsmanagedobjectmodel/entitiesbyname.md)
