Re: Core Data Abstractions
Re: Core Data Abstractions
- Subject: Re: Core Data Abstractions
- From: Evan DiBiase <email@hidden>
- Date: Mon, 30 May 2005 15:39:19 -0400
On May 30, 2005, at 2:02 PM, mmalcolm crawford wrote:
Why are you writing the fetch requests? Are you doing this instead of simply traversing a relationship? See:
The one of the top-level container entities in my application are "ActionList"s; they have a to-many relationship to "Action" entities. I'm using fetch requests in the situation where, for example, I'd like to see if I need to create a default set of ActionLists (by checking to see if any are already in the store). That seems to be about the only case in which I'd need a fetch request, so perhaps this is less of an issue than I originally though.
How are you creating the new instances of your entities? The NSEntityDescription method makes it a lot easier: NSManagedObject *newEmployee = [NSEntityDescription insertNewObjectForEntityForName:@"Project" inManagedObjectContext:context];
Quite so. That's the method I'm using, and it seems to work well. Finally, of course, using Cocoa Bindings will also cut out a lot of code, if that's an option.
Bindings are definitely helping, although I'm struggling to apply my half-baked bindings without Core Data knowledge to form a fully-baked bindings with Core Data representation in my head. I think I'm getting there. Alternatively, you can remove a lot of repetitive code by creating and using fetch request templates:
NSError *error = nil; NSFetchRequest *fr = [[self managedObjectModel] fetchRequestTemplateForName:@"AllProjects"]; NSArray *projects = [[self managedObjectContext] executeFetchRequest:fr error:&error];
That's perfect. Much cleaner than the code I have been writing. It seems like templates are the way to go for me here.
Thanks!
Evan |
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden