我无法找出我的代码有什么问题。我试图在Swift中使用MagicalRecord。当我做简单的createEntity时,它给了我nil:
let a = Subject.MR_createEntity() <--- This line is working perfectly
let b = Points.MR_createEntity() <--- This line returns nil
let c = Class.MR_createEntity() <--- This line returns nil
这是我的类实现:
主题:
@objc(Subject)
class Subject: NSManagedObject {
@NSManaged var name: String?
@NSManaged var classes: NSSet?
}
类别:
@objc(Class)
class Class: NSManagedObject {
@NSManaged var name: String?
@NSManaged var teacherName: String?
@NSManaged var subject: Subject?
@NSManaged var points: NSSet?
}
点数:
@objc(Points)
class Points: NSManagedObject {
@NSManaged var date: NSDate?
@NSManaged var points: NSNumber?
@NSManaged var maxPoints: NSNumber?
@NSManaged var classType: Class?
}
答案 0 :(得分:1)
初始化MagicalRecord时,您可以启用 核心数据 日志,然后您就会知道无法创建实体时会发生什么。
MagicalRecord.setLoggingLevel(MagicalRecordLoggingLevel.Warn)
答案 1 :(得分:0)
解决方案:
一切正常。