I have the following factory method. I’m just wondering if the assignment
self = [NSEntityDescription insertNewObjectForEntityForName:entityName
inManagedObjectContext:[self managedObjectContext]];
is correct, given the fact that my class is a subclass of NSManagedObject
thanks
+ (CBItem *)insertEntityForName:(NSString*)entityName fromXMLElement:(NSXMLElement*)xmlElement withQueryType:(CBSearchQueryType)queryType inContext:(NSManagedObjectContext *)inContext
...
self = [NSEntityDescription insertNewObjectForEntityForName:entityName
inManagedObjectContext:[self managedObjectContext]];
...
return self;
No, this is not correct. You only assign to
selfinside aninitmethod. For a factory type method, you should be returning a variable, e.g.