NSDocument:无法自动保存文档.该文件已被另一个应用程序更改 [英] NSDocument: The document could not be autosaved. The file has been changed by another application

查看:337
本文介绍了NSDocument:无法自动保存文档.该文件已被另一个应用程序更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对帖子标题的搜索表明它很常见;确实,我已经从Xcode中得到了这个错误.但是我似乎找不到任何修复.我现在在运行程序时看到它,它似乎发生在调用changeCountTokenForSaveOperation的过程中或之后.看来这与撤消管理器有关,而不是与我在使用核心数据有关,但是我可能错了.

A search on the title of this post reveals that it's pretty common; indeed, I've gotten this error from Xcode. But I can't seem to find any fixes. I'm seeing it now when I run my program, and it appears to occur during or after changeCountTokenForSaveOperation is called. It seems related to the undo manager, rather than to the fact that i'm using core data, but I may be wrong.

有人知道是什么原因或如何解决此问题吗?

Does anyone know what causes this or how to fix it?

推荐答案

问题是手动保存managedObjectContext.因此正确的解决方案是避免手动保存.如果无法避免,则可以重写NSDocument的fileModificationDate方法以返回文件的当前文件修改日期.这样,文档不会显示错误消息.

The problem is saving manually the managedObjectContext. So the correct solution is avoid saving manually. If you cannot avoid it, you can override fileModificationDate method of NSDocument to return the current file modification date of the file. Of this way the document does not show the error message.

- (NSDate *)fileModificationDate {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSDictionary *attrs = [fileManager attributesOfItemAtPath:self.fileURL.path error:NULL];
    return attrs[NSFileModificationDate];
}

这篇关于NSDocument:无法自动保存文档.该文件已被另一个应用程序更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆