Re: Determine if a document is "new"
Re: Determine if a document is "new"
- Subject: Re: Determine if a document is "new"
- From: Martin Hewitson <email@hidden>
- Date: Sun, 23 May 2010 13:36:00 +0200
I believe you might be looking for:
- (id)initWithType:(NSString *)typeName error:(NSError **)outError
which you can implement in your NSPersistentDocument subclass. I've done it this way before; I also did the following steps to give the user a new document that has no changes:
1) disable undo on the managed object context
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
[[managedObjectContext undoManager] disableUndoRegistration];
2) do changes to the core data model
3) re-enable undo on the moc
[managedObjectContext processPendingChanges];
[[managedObjectContext undoManager] enableUndoRegistration];
One problem that arises here is to handle the fact that the new document has not been saved so far, so if you need access to the filepath for the new document, you need to get the user to save the new document straight away, and bail out if they decline.
Cheers,
Martin
On May 23, 2010, at 1:24 PM, Bryan Zarnett wrote:
> I have a Document-based core data application ( from template). I would like to determine in "MyDocument" if the file is new -- has no content so that I can populate a few of the models with required default data.
>
> I was wondering what is the base way to approach this? I didn't see any particular API like IsNewDocument() which would have been handy!
>
> Thoughts?
>
> Bryan
>
>
> _______________________________________________
>
> 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: email@hidden
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
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