configurePersistentStoreCoordinator not called for saveAs NSPersistentDocument

后端 未结 4 1493
醉梦人生
醉梦人生 2021-01-21 11:18

I experience an odd behaviour regarding saving an NSPersistentDocument. I can create a new document which is autosaved without an issue. But when I save it write(to: ofTyp

4条回答
  •  借酒劲吻你
    2021-01-21 11:34

    Good news and bad news

    I have succeeded to reproduce the exact same error with Xcode 9.2 running on MacOS 10.13.2.

    1. The version 1 of document file is still in a Autosave directory.
    2. Document.xcdatamodel is updated to version 2 (Document 2.xcdatamodel)
    3. When the application starts, the file of version 1 in the Autosave directory is read with NSBinaryStoreSecureDecodingClasses option.
    4. The app works well.
    5. File > Save... triggers NSPersistentStoreCoordinator .migratePersistentStore() aka -[NSPersistentStoreCoordinator migratePersistentStore:toURL:options:withType:error:]:
    6. During the course of migratePersistentStore, NSBinaryStoreSecureDecodingClasses option is not set for both writing to and reading from a temporary file.
    7. The error occurs.

    Somewhat strange for me. Why the migration is executed upon saving, instead of upon opening a file? The lightweight migration has been already done at the step 3?

    EDIT:

    It seems that the name of migratePersistentStore does not mean migration from old version to new version. It seems to mean migrate from an old persistent store with an old URL aka filename and/or file format to a new persistent store with a new URL and/or file format. So it is called when Save As... or Saving a new document which is already saved in an Autosave directory.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题