我想知道正确的方法是创建我自己的子类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]);
}
}
答案 0 :(得分:0)
刚发现NSManagedObject reference说:
如果您实例化托管对象 直接,您必须致电指定 初始化 (initWithEntity:insertIntoManagedObjectContext:)。