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