保存主对象上下文时,CoreData崩溃

时间:2019-02-05 14:39:17

标签: ios swift core-data nscoding

当我将应用程序移至后台时,CoreData似乎在保存mainObjectContext后立即崩溃。在控制台中,我看到以下错误:

CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x6000064c7ac0> , -[_SwiftValue encodeWithCoder:]: unrecognized selector sent to instance 0x60000319de00 with userInfo of (null)

保存主对象上下文的方法是这样实现的:

func save() {
    if mainManagedObjectContext.hasChanges {
        mainManagedObjectContext.performAndWait {
            do {
                try mainManagedObjectContext.save()
            } catch {
                NotificationCenter.default.post(name: .ManagedObjectContextSaveError, object: nil)
            }
        }
        NotificationCenter.default.post(name: .MainManagedObjectContextSaved, object: nil)
    }
}

此方法从AppDelegate.applicationWillResignActive(_:)中调用 我不确定为什么在这里调用encodeWithCoder以及为什么会崩溃。

实际上,我什至不知道如何从这里进一步解决问题。

0 个答案:

没有答案