[英]SIGABRT after NSManagedObjectContext = [NSEntityDescription …]
[英]NSEntityDescription.entity crashes app (SIGABRT)
包含NSEntityDescription.entity
的行崩溃并给我错误
主题 1:SIGABRT
我看到其他人问过这个问题,推荐的答案是简单地从头开始删除和重新制作实体。 我已经这样做了很多次,我还彻底“清理”了代码,并在我的AppDelegate.swift
文件和这个ViewController
文件中导入了 CoreData。 有人有建议吗?
override func viewDidLoad() {
super.viewDidLoad()
addGesture()
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
let managedContext = appDelegate.persistentContainer.viewContext
let stringModelEntity = NSEntityDescription.entity(forEntityName: "StringModels", in: managedContext)!
let stringBundle = NSManagedObject(entity: stringModelEntity, insertInto: managedContext)
self.getJSON(stringBundle)
do {
try managedContext.save()
} catch let error as NSError {
print("Could not save. \(error), \(error.userInfo)")
}
}
编辑
由于最终打开调试器,我找到了一个解决方案,以下链接的“最佳答案”描述并解决了这个问题:核心数据:加载模型失败
这意味着它无法找到名为“StringModels”的实体。 根据我的经验,错误 SIGABRT 是当程序认为应该存在的东西不存在时引起的。
我会检查大小写和拼写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.