• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data Abstractions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data Abstractions


  • Subject: Re: Core Data Abstractions
  • From: Lee Morgan <email@hidden>
  • Date: Mon, 30 May 2005 12:13:00 -0400


On May 30, 2005, at 11:51 AM, Evan DiBiase wrote:

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.

Well, I don't know that this is the best solution... but what I plan on doing (scheduled for work) is create a category for NSManagedObject with a "executeFetchRequestForEntityName:predicate:context:" method
I plan to allow for a nil predicate and / or context - if context is nil I will simply call [self managedObjectContext];

Like I said, I don't know if this is the best solution - for that matter I don't know what problems may come from it being a category to NSManagedObject since I haven't had time to implement it yet.

- lee
 _______________________________________________
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

References: 
 >Core Data Abstractions (From: Evan DiBiase <email@hidden>)

  • Prev by Date: Re: Core Data Abstractions
  • Next by Date: Problem using Java 5.0 on Xcode...
  • Previous by thread: Re: Core Data Abstractions
  • Next by thread: Problem using Java 5.0 on Xcode...
  • Index(es):
    • Date
    • Thread