如何在Swift中打印出Core Data保存错误

Ján*_*nos 0 core-data ios swift

如何在Swift中打印出Core Data保存错误?

至于我有这两行:

var error: AutoreleasingUnsafePointer<NSError?> = nil
let success = managedObjectContext.save(error)
Run Code Online (Sandbox Code Playgroud)

pol*_*war 8

 func saveContext () {
    if managedObjectContext.hasChanges {
        do {
            try managedObjectContext.save()
        } catch let nserror as NSError {
            // Replace this implementation with code to handle the error appropriately.
            // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
            print("Unresolved error \(nserror), \(nserror.userInfo)")
            abort()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)