Re: minimum one entity instance on initial launch
Re: minimum one entity instance on initial launch
- Subject: Re: minimum one entity instance on initial launch
- From: Gonzalo Castro <email@hidden>
- Date: Fri, 10 Aug 2007 16:52:44 -0400
On Aug 8, 2007, at 3:36 PM, Jim Thomason wrote:
I want there to be at least one entity instance on initial launch of
the application, including any launch following the user deleting the
persistent storage file. What's the best way to ensure this?
Couple of thoughts -
1) Are you ensuring in the interface that the user must have at least
one object? If not, you should. Bind your delete button's "enabled" on
your array controller to some parameter that returns true if there's
more than 1 item, and false if there's only 1. That way they can never
get down below 1.
Yes, I've done this.
2) The CoreData project template has some code in it that creates the
persistent store file if it doesn't exist. That looks like a good
place to wire into, and you're assured it's only called when the file
is created.
In looking at the template code I see a method
- (NSPersistentStoreCoordinator *) persistentStoreCoordinator
But here the managed objects aren't loaded yet, as far as I can tell.
Instead of looking to see how many entity instances are restored, is
the only solution to check if the store file exists in this method
and if
it does not exist assume I need to create an entity instance and add
it to the object context?
I would have preferred checking on the count of MOs restored in case
the store file was somehow corrupted, etc.
3) If it's document based, you can do something to create the object
if the user is opening a new file. Is there a clean method for this? I
don't recall offhand. At a minimum, you could check for [self fileURL]
== nil in windowControllerDidLoadNib, I think, and add an object
there. Is there some easier delegate based "New Document Created"
method or note or something? I guess you could subclass
NSDocumentController.
It's not a document based app.
And from there I wouldn't worry about it. That creates a default and
ensures that the user can't delete it. Technically, they could
manually edit the persistent file and delete the sole object, but if
they do that they get what's coming to 'em.
-Jim.....
_______________________________________________
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