2011-06-01 62 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做這種方式。

回答

相關問題