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]);
}
}