问题描述
||
我想知道正确的方法是创建属于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 :)。