如何为子类NSManagedObject正确实现自定义初始化程序

|| 我想知道正确的方法是创建属于NSManagedObject的类的自己的初始化程序。 目前,我正在像这样初始化:
-(id)initWithXML:(TBXMLElement *)videoXML
{
    // Setup the environment for dealing with Core Data and managed objects
    HenryHubAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    NSEntityDescription *entityHubPieceVideo = [NSEntityDescription entityForName:@\"HubPieceVideo\" 
                                                           inManagedObjectContext:context];

    self = [[HubPieceVideo alloc] initWithEntity:entityHubPieceVideo insertIntoManagedObjectContext:context];
    // do stuff and then save

    NSError *error;
    if(![context save:&error]) 
    {
        NSLog(@\"HubPiece video save context error: %@ %@\", error, [error userInfo]); 
    }
}
好像其他人也这样做。     
已邀请:
        刚刚发现NSManagedObject参考说明:   如果实例化一个托管对象   直接,您必须致电指定   初始化器   (initWithEntity:insertIntoManagedObjectContext :)。     

要回复问题请先登录注册