'这个NSPersistentStoreCoordinator没有持久存储(未知)。它无法执行保存操作。

时间:2017-09-05 10:52:52

标签: ios swift cocoa-touch core-data iphonecoredatarecipes

我在“尝试保存()”此行遭遇崩溃。

`$cookies.getObject('myFavoritec');

}

在appdelegte中,appDidFinishLaunching:我写过:

extension NSManagedObjectContext {

/// Only save if `hasChanges`
func saveIfNeeded() throws {
    guard hasChanges else {
        return
    }

    do {
        try save()
    } catch {
        assertionFailure("Failed to save main context: \(error)")
        throw error
    }
}

/// Calls `saveIfNeeded` and then calls `saveIfNeededUpToRootContext()` on the `parentContext`.
func saveIfNeededUpToRootContext() throws {
    try saveIfNeeded()
    try parent?.saveIfNeededUpToRootContext()
}

基本上调用上面的方法:saveIfNeededUpToRootContext。

以下是DataStore的初始化:

defer {
            do {
                try DataStore.mainContext.saveIfNeededUpToRootContext()
            } catch {
                log("Failed to save \"App Feedback\" to Core Data: \(error)")
            }
        }

0 个答案:

没有答案