• 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
Core Data Abstractions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data Abstractions


  • Subject: Core Data Abstractions
  • From: Evan DiBiase <email@hidden>
  • Date: Mon, 30 May 2005 11:51:19 -0400

Hi!

I'm working on a new application that uses Core Data, and I really like what I've seen so far. An issue that's come up, however, is that I seem to be sprinkling a lot of fetch requests and new entity insertions around my code. It seems to me that it would be cleaner to hide a lot of this Core Data work behind some abstractions, but I'm having some trouble coming up with ones that seem appropriate.

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.

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

  • Follow-Ups:
    • Re: Core Data Abstractions
      • From: Lee Morgan <email@hidden>
    • Re: Core Data Abstractions
      • From: Vincent Coetzee <email@hidden>
  • Prev by Date: Re: NSArrayController question...
  • Next by Date: Re: Core Data Abstractions
  • Previous by thread: Re: IB, TableViews and exposing bindings for a Subclassed NSActionCell
  • Next by thread: Re: Core Data Abstractions
  • Index(es):
    • Date
    • Thread