答案 0 :(得分:0)
这是关于隐式和显式指定实体名称的问题
guard let appDelegate =
UIApplication.shared.delegate as? AppDelegate else {
return
}
let managedContext =
appDelegate.persistentContainer.viewContext
1-这将根据类Person
表示的名为CustomObj
的实体创建一个对象,并将其插入managedContext
let entity =
NSEntityDescription.entity(forEntityName: "Person",
in: managedContext)!
let person1 = CustomObj(entity: entity, insertInto: managedContext)
2-这将从类CustomObj
中创建一个对象,其中实体名称为CustomObj
,并将其插入managedContext
let person2 = CustomObj(context: managedContext)
class CustomObj:NSManagedObject {
}