insertNewObject(forEntityName:into:)
Creates, configures, and returns an instance of the class for the entity with a given name.
Declaration
class func insertNewObject(forEntityName entityName: String, into context: NSManagedObjectContext) -> NSManagedObjectParameters
- entityName:
The name of an entity.
- context:
The managed object context to use.
Return Value
A new, autoreleased, fully configured instance of the class for the entity named entityName. The instance has its entity description set and is inserted it into context.
Discussion
This method makes it easy for you to create instances of a given entity without worrying about the details of managed object creation. The method is conceptually similar to the following code example.
NSManagedObjectModel *managedObjectModel =
[[context persistentStoreCoordinator] managedObjectModel];
NSEntityDescription *entity =
[[managedObjectModel entitiesByName] objectForKey:entityName];
NSManagedObject *newObject = [[NSManagedObject alloc]
initWithEntity:entity insertIntoManagedObjectContext:context];
return newObject;