One of my issues, in particular, is that I seem to be writing code like this a lot:
NSError *fetchError = nil;
NSArray *fetchedLists;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
@try {
NSEntityDescription *projectListEntity =
[NSEntityDescription entityForName:@"ProjectList"
inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:projectListEntity];
fetchedLists = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&fetchError];
} @finally {
[fetchRequest release];
}
This strikes me as a pretty verbose segment of code to use every time I'd like to fetch all of the ProjectList entities from a managed object context. My first thought would be that something like this deserves to be refactored out into a class method on a custom NSManagedObject subclass for the ProjectList entity, something like + (NSArray *)executeFetchRequest:(NSFetchRequest *) inManagedObjectContext:(NSManagedObjectContext *), but that feels wrong to me, too. (Plus, there'd be a bunch of duplicated code, and I'd have to make custom subclasses for most of my entities.)
Any advice or discussion would be greatly appreciated. Core Data seems well-designed and internally consistent, and I hope that figuring out the answers to abstraction questions like these will help me to understand the Core Data framework as a whole.