【发布时间】:2013-04-20 05:19:34
【问题描述】:
在使用 Core Data 时,我发现我的 UIManagedDocument 对象的 documentState 等于 5。UIDocument documentation 只定义了这些常量:
enum { UIDocumentStateNormal = 0,
UIDocumentStateClosed = 1 << 0,
UIDocumentStateInConflict = 1 << 1,
UIDocumentStateSavingError = 1 << 2,
UIDocumentStateEditingDisabled = 1 << 3 }; typedef NSInteger UIDocumentState;
这将是 0、1、2、4 和 8。5 可能是 UIManagedDocument 使用的特殊状态,但我在任何地方都找不到它的文档。当核心数据模式改变时,状态似乎发生了。我不知道国家是什么意思。我通常会收到错误:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.',这是有道理的,因为文档需要以正常状态打开才能用作持久存储。
现在我只是检查状态是否等于 5,并在发生这种情况时删除持久存储并重新创建它。但是一旦我的应用程序上线并存储用户数据,我就不想这样做了。我还没有研究过迁移核心数据模式的最佳实践,但是在我的代码中检查managedDocument.documentState == 5 似乎也有点混乱。任何地方都没有关于此文档状态的任何文档吗?
更新: 现在我正在查看它,这些常量按原样定义的原因是可以将它们按位或一起作为掩码进行按位或运算,这是有道理的。所以 documentState 等于 5 意味着它既是 UIDocumentStateClosed 也是 UIDocumentStateSavingError。不过,这些错误非常普遍。我将如何缩小根本原因?
此外,我看到的用于检查这些文档状态的所有示例代码都显示检查是否相等,即if (managedDocument.documentState == UIDocumentStateClosed),但这意味着这是不正确的,应该按位检查,即@987654333 @。
【问题讨论】:
标签: core-data uimanageddocument schema-migration