An NSEntityDescription object describes an entity in Apple Core Data framework. It is available in OS X v10.4 and later and available in iOS 3.0 and later. Its objects are primarily used by the Apple Core Data Framework for mapping entries in the persistent store to managed objects in the application.
An NSEntityDescription object is associated with a specific class whose instances are used to represent entries in a persistent store in applications using the Core Data Framework. Minimally, an entity description should have:
- A name
- The name of a managed object class (If an entity has no managed object class name, it defaults to NSManagedObject.)
NSEntityDescription class reference Source Using Entity Descriptions in Dictionaries
NSEntityDescription’s copy method returns an entity such that
[[entity copy] isEqual:entity] == NO
NSEntityDescription
supports the NSFastEnumeration
protocol. You can use this to enumerate over an entity’s properties, as illustrated in the following example:
NSEntityDescription *anEntity = ...;
for (NSPropertyDescription *property in anEntity) {
// property is each instance of NSPropertyDescription in anEntity in turn
}
NSManagedObjectContext *context = <#Get the context#>;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@" <#Entity name#>"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSError *error;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
if (fetchedObjects == nil) {
// Handle the error.
}