【问题标题】:Sigabrt with error that class must have a valid NSEntityDescriptionSigabrt 错误,该类必须具有有效的 NSEntityDescription
【发布时间】:2018-12-06 11:49:13
【问题描述】:

正如您在标题中看到的那样,我收到了一个 Sigabrt 错误,该类必须具有有效的 NSEntityDescription。我的答案是我必须添加到我的项目中以及我必须在哪里实现它。如果这是一个明显的问题,请不要评判我,因为我刚刚开始使用 SwiftCore Data 编码。

import UIKit
import CoreData

@objc (Trancsaction)
public class Trancsaction: NSManagedObject {
    var date: Date?{
        get{
            return rawDate as Date?
        }
        set {
            rawDate = newValue as NSDate?
        }
    }
    convenience init?(money: Double, date: Date?, reason: String?) {
        let appDelegate = UIApplication.shared.delegate as? AppDelegate

        guard let context = appDelegate?.persistentContainer.viewContext else {
            return nil
        }
        self.init(entity: Trancsaction.entity(), insertInto: context)

        self.reason = reason
        self.money = money
        self.date = date
    }
}

【问题讨论】:

  • 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“类 'Your Class' 的 NSManagedObject 必须具有有效的 NSEntityDescription。”尝试定义//@objc(Your Class) public class YourClass: NSManagedObject { }检查这个
  • 你能怎么一些代码??
  • @iOS.Wolf 我添加了核心数据类代码
  • @RohitMagdum 我已经有了这个:我将这部分代码添加到我的问题中。
  • entity() 是如何定义的?为什么是一个失败的初始化器?如果AppDelegate 丢失,应用程序甚至会启动,并且托管对象上下文应该是非可选的。

标签: swift xcode core-data error-handling sigabrt


【解决方案1】:

尝试评论此行@objc (Trancsaction)

//@objc (Trancsaction)
public class Trancsaction: NSManagedObject {

【讨论】:

    猜你喜欢
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2023-03-24
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多