2011-06-01 60 views
1

我想知道什么是正确的方法是创建我自己的子类化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]); 
    } 
} 

好像some别人also做这种方式。

回答

相关问题