应用程序终止时如何消除核心数据sqlite警告消息?

clo*_*der 4 sqlite macos cocoa core-data swift

自升级为High Sierra以来,我的核心数据应用程序终止时一直收到以下警告:

libsqlite3.dylib的客户端中的错误:API违反损害了数据库完整性:vnode在使用中未链接

我还没有看到任何实际的问题,但是我想知道是否应该在applicationShouldTerminate()中添加一些拆卸代码?

目前,我所要做的就是保存上下文,如果上下文有更改,则返回.terminateNow。

clo*_*der 5

好,我知道了。由于我的持久性存储中包含敏感数据,因此在关闭之前,我将对磁盘上的文件进行加密是最后一步。但是,在关闭过程中,Core Data堆栈此时仍在引用它们。

解决方案是在运行代码加密文件之前添加代码以删除持久性存储。

    for store in managedObjectContext!.persistentStoreCoordinator!.persistentStores {
        try! managedObjectContext!.persistentStoreCoordinator!.remove(store)
    }
Run Code Online (Sandbox Code Playgroud)