• 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: CoreData: Can't modify an immutable model
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData: Can't modify an immutable model


  • Subject: Re: CoreData: Can't modify an immutable model
  • From: Ben Trumbull <email@hidden>
  • Date: Tue, 5 Feb 2008 14:18:37 -0800

At 5:04 PM -0500 2/5/08, Sean McBride wrote:
Ben,

Are you talking about insertNewObject
ForEntityForName:inManagedObjectContext: ?  Do I understand correctly
that the moc parameter is in fact optional?  The docs don't say so, but
I have always wished it was the case.  Can you confirm?  (I'd like to be
able to set some attributes before NSObjectControllers go changing the UI).

Yes it is optional, but it's not for the faint of heart. You won't get relationship maintenance, undo, or the standard notifications until you call -insertObject:


This is documented under NSManagedObject's designated initializer, which the convenience method on NSEntityDescription eventually invokes.

Incidentally, on 10.5, if you're working with a large batch of new objects, it's a lot faster to look up the entity description once and use:

MySubclass* mo = (MySubclass*)[[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:moc];

This works as NSManagedObject's +alloc always allocates the correct Class for the entity you pass into the initializer. Effectively, NSManagedObject is a class cluster for the subclasses in your model. On Tiger, you'd have to do that yourself.
--


-Ben
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: CoreData: Can't modify an immutable model (From: Ben Trumbull <email@hidden>)
 >Re: CoreData: Can't modify an immutable model (From: "Sean McBride" <email@hidden>)

  • Prev by Date: Re: stringWithContentsOfURL returns nil
  • Next by Date: Re: NSDrawerOpeningState woes
  • Previous by thread: Re: CoreData: Can't modify an immutable model
  • Next by thread: Re: CoreData: Can't modify an immutable model
  • Index(es):
    • Date
    • Thread