ios - NSEntityDescription.entity crashes app (SIGABRT)
问题描述
The line containing NSEntityDescription.entity
is crashing and giving me the error
Thread 1: SIGABRT
I have seen other people ask this question, the recommended answer is to simply delete and remake the entity from scratch. I have done this many times, I have also "cleaned" the code thoroughly, and imported CoreData in both my AppDelegate.swift
files and this ViewController
file. Does anyone have any advice?
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)")
}
}
EDIT
I've found a solution thanks to finally opening the debugger, the following link's 'best answer' describes and solves this issue: Core data: Failed to load model
解决方案
This will mean that it cannot find the entity with the name "StringModels". In my experience, the error SIGABRT is caused when something that the program thinks should exist does not.
I would check capitalization and spelling.
推荐阅读
- ignite - 如何更改 Apache Ignite 的 REST API 端口?
- java - 创建像 Spring DataSourceBuilder 一样工作的自定义构建器?
- android - Chrome 更新后未加载 Android 9 WebView(也是 admob 广告)
- cordova - 免费后如何检测用户是否购买了该应用程序?
- kotlin - 值不会在简单的计算中相加
- firebase - 如何获取文档数据并将其设置在屏幕上
- r - 使用百分比时的美学分组论点
- java - Android Pjsip:音频电话会议
- php - 邮件程序错误:SMTP 连接()失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 在我的代码中
- android - 当我将 `sqflite` 添加到我的 pubspec.yaml 时,为什么我的颤振应用程序会崩溃?