错误提示类必须具有有效的NSEntityDescription

时间:2018-06-27 14:19:21

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

正如您在标题中看到的那样,我收到一个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
    }
}

1 个答案:

答案 0 :(得分:0)

尝试评论此行@objc (Trancsaction)

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