• 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: Default Instance of entity in Core Data Document
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Default Instance of entity in Core Data Document


  • Subject: Re: Default Instance of entity in Core Data Document
  • From: Adam Knight <email@hidden>
  • Date: Tue, 31 Jul 2007 12:57:19 -0500

On Jul 31, 2007, at 12:26 PM, Frank Schmitt wrote:

I've run into two snags along the way:

First, I need to check for an instance of the entity once my managedObjectContext is finished loading, and add one if it's missing. Where is the right place to do this? awakeFromNib seems to be too early (the objects aren't loaded yet), and I can't do the usual trick of adding an observer to the object controller's "content" key, since it won't ever fire if the file contains no instances of the entity.

Use windowControllerDidLoadNib in NSDocument for that. I use this myself to check to see if fileURL is set and if not then I insert a blank entity for editing so the document is useful from the start.


The second snag is that modifying the file after it's created always brings up a "Save Changes?" sheet. I imagine I could reset this with updateChangeCount, but that seems hackish. Is that in fact the right way to do this?

[[[self managedObjectContext] undoManager] disableUndoRegistration]; //Do something to the context [[self managedObjectContext] processPendingChanges]; [[[self managedObjectContext] undoManager] enableUndoRegistration];

Beware the evils of calling methods that call other methods that change the context. That's where processPendingChanges comes in as sometimes those changes happen after the event loop is done and you've turned undo registration back on (or so it does in my little world). If you're not seeing that, then you don't need that line (not that it hurts anything to use it on a store with just one object...).

Ideally I could change the "blank slate" state of the managed object context to include one instance of the entity with the default values that I've assigned in the data model editor. Is there a way to do that?

Nope.



Adam Knight
codepoetry - http://www.codepoetry.net/products/

_______________________________________________

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


  • Follow-Ups:
    • Re: Default Instance of entity in Core Data Document
      • From: mmalc crawford <email@hidden>
References: 
 >Default Instance of entity in Core Data Document (From: Frank Schmitt <email@hidden>)

  • Prev by Date: Re: Default Instance of entity in Core Data Document
  • Next by Date: applicationWillTerminate and NSDocumentController
  • Previous by thread: Re: Default Instance of entity in Core Data Document
  • Next by thread: Re: Default Instance of entity in Core Data Document
  • Index(es):
    • Date
    • Thread