ios - 如何在 Swift 中打印出核心数据保存错误

标签 ios core-data swift

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

据我所知,有这两行:

var error: AutoreleasingUnsafePointer<NSError?> = nil
let success = managedObjectContext.save(error)

最佳答案

 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()
        }
    }
}

关于ios - 如何在 Swift 中打印出核心数据保存错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24930347/

相关文章:

ios - iOS 上像素完美的验收测试

应用程序被杀死/关闭/未打开时的 IOS 推送通知操作

swift - 如何从核心数据中的关系中获取值(swift)

ios - SpriteKit/Swift 中向上滑动角色跳跃

ios - 分段控件上的 Swift 句柄操作

ios - 如何在 iOS 中使用 UIView 动画显示类似 UIAction 表的 UIView?

ios - 操作无法完成。 (com.facebook.sdk.core 错误 3.)

cocoa - 在核心数据中创建 "lookup"值

ios - 核心数据 : using undefined transient attribute

ios - 如何在 Swift 中引用导航 Controller ?