What is the difference, in terms of outcome, between the 2 following methods:
+ (id)insertNewObjectForEntityForName:(NSString *)entityName inManagedObjectContext:(NSManagedObjectContext *)context;
+ (NSEntityDescription *)entityForName:(NSString *)entityName inManagedObjectContext:(NSManagedObjectContext *)context;
When should I use each one of them?
insertNewObjectForEntityForName
creates an instance of the entity and adds it to the context. The context is now dirty and needs to be saved. The returned instance is a subclass ofNSManagedObject
.entityForName
returns theNSEntityDescription
instance which describes the entity, what attributes and relationships it has, how they are constructed. The context is not modified in any way.