簡體   English   中英

NSEntityDescription.entity 使應用程序崩潰(SIGABRT)

[英]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)")
    }
}

Stack Overflow 還不允許我嵌入圖像,但這里是 Models.xcdatamodeld 文件。

編輯

由於最終打開調試器,我找到了一個解決方案,以下鏈接的“最佳答案”描述並解決了這個問題:核心數據:加載模型失敗

這意味着它無法找到名為“StringModels”的實體。 根據我的經驗,錯誤 SIGABRT 是當程序認為應該存在的東西不存在時引起的。

我會檢查大小寫和拼寫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM