On 2011 Jul 31, at 11:29, Quincey Morris wrote:

> The problem is that I can't think of any reason why it would be acceptable 
> for an application to save a document without the user's consent (it takes 
> away the user's ability to, at the very least, close the document *without* 
> saving changes, which turns the application into a ticking time bomb) ...
> 
> OR
> 
> ... (if you have a genuine justification for taking the Save metaphor away 
> from the user) why you would use NSPersistentDocument at all, rather than 
> using Core Data directly, including [NSManagedContext save:] to push your 
> changes to the persistent store.

OR is good advice.  Be careful if you want to mix these metaphors.  Invoking 
[NSManagedObjectContext save:] will cause the dreaded "file has been changed by 
another application" warning if user subsequently dirties and saves it. You can 
usually fix that by defining in your document and invoking this method:

- (void)syncFileModificationDate {
    NSFileManager* fm = [NSFileManager defaultManager] ;
    NSDictionary* fileAttributes = [fm fileAttributesAtPath:[[self fileURL] 
path]
                                               traverseLink:NO] ;
    NSDate* newModificationDate = [fileAttributes 
objectForKey:NSFileModificationDate] ;
    [self setFileModificationDate:newModificationDate] ;
}

But I would try Mike Abdullah's idea first.  When messing with the Cocoa 
document architecture, the lower level at which you mess, the more trouble 
you're going to have.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to