![](/img/trans.png)
[英]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.