如何为子类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]);
}
}
好像其他人也这样做。
没有找到相关结果
已邀请:
1 个回复
信藉乒