Re: Default Instance of entity in Core Data Document
Re: Default Instance of entity in Core Data Document
- Subject: Re: Default Instance of entity in Core Data Document
- From: mmalc crawford <email@hidden>
- Date: Tue, 31 Jul 2007 11:08:11 -0700
On Jul 31, 2007, at 10:57 AM, Adam Knight wrote:
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.
Assuming the common pattern where you want to create an instance of an
object when the document is first created and never delete it
thereafter, you should use initWithType:error: instead -- see:
<http://developer.apple.com/documentation/Cocoa/Conceptual/NSPersistentDocumentTutorial/04_Department/chapter_5_section_2.html
>
If you subsequently need to do other store-related setup, you should
almost certainly use
configurePersistentStoreCoordinatorForURL:ofType:error:.
mmalc
_______________________________________________
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