我是否可以在不通过NSEntityDescription的情况下创建自定义托管对象类的新实例?

ope*_*rog 7 iphone macos cocoa cocoa-touch core-data

从Apple的例子来看,我有这个:

Event *event = (Event*)[NSEntityDescription 
    insertNewObjectForEntityForName:@"Event" 
             inManagedObjectContext:self.managedObjectContext];
Run Code Online (Sandbox Code Playgroud)

Event继承自NSManagedObject.有没有办法避免这种奇怪的NSEntityDescription调用,而只是alloc+init某种程度上直接Event类?我是否必须编写自己的初始化程序才能执行上述操作?或者NSManagedObject已经足够智能了吗?

Ale*_*lex 5

NSManagedObject提供一种叫做的方法initWithEntity:insertIntoManagedObjectContext:.你可以用它来做一个更传统的alloc/ init对.请记住,此返回的对象不是自动释放的.