NSEntityDescription.entity使应用程序崩溃(SIGABRT)

时间:2018-07-17 23:02:02

标签: ios swift xcode core-data nsentitydescription

包含“ NSEntityDescription.entity”的行崩溃,并给我错误Thread 1:SIGABRT。

我已经看到其他人问这个问题,建议的答案是简单地从头开始删除并重新制作实体。我已经做了很多次,我还彻底“清理”了代码,并将CoreData导入了AppDelegate.swift文件和此ViewController文件中。有人有建议吗?

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

Stack Overflow will not let me embed images yet, but here is the Models.xcdatamodeld file.

******编辑****** 由于最终打开了调试器,我找到了一个解决方案,以下链接的“最佳答案”描述并解决了此问题:Core data: Failed to load model

1 个答案:

答案 0 :(得分:0)

这将意味着它找不到名称为“ StringModels”的实体。以我的经验,当程序认为不应该存在的某些内容时,就会导致错误SIGABRT。

我会检查大小写和拼写。

相关问题