如何在 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/