On 2012 Mar 07, at 23:48, Martin Hewitson wrote:

> I have an app which works with autosave and Versions browser.

Oh, so you've implemented +[NSDocument autosavesInPlace]  ;)

> I have a file-monitor in the app which reloads the document if it changes on 
> disk.

Great feature.  I've done that too.

> For the reloading I was simply calling -revertDocumentToSaved: …

If your document is Core Data, forget it.  You'll need to close and re-open.  
Ugly, but at least it doesn't display any errors and you'll be able to ship 
sometime this year.

> "The document “foo.txt” could not be saved. The file has been changed by 
> another application."


I've successfully beaten that monster a couple times with the following method. 
 It looks silly, but it works.  Try sprinkling one in during your reload 
somewhere…
 
@implementation NSDocument (SyncModDate)

- (void)syncFileModificationDate {
    NSFileManger* fm = [NSFileManager defaultManager] ;
    NSDictionary* fileAttributes = [fm attributesOfItemAtPath:[[self fileURL] 
path]
                                                        error:NULL] ;
    NSDate* newDate = [fileAttributes objectForKey:NSFileModificationDate] ;
    [self setFileModificationDate:newDate] ;
}

@end

I think I got the idea from here:

http://stackoverflow.com/questions/380076/manual-core-data-schema-migration-without-document-changed-warning


_______________________________________________

Cocoa-dev mailing list ([email protected])

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

This email sent to [email protected]

Reply via email to