如何解决如何为子类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]);
}
}
好像其他人也这样做。
解决方法
刚刚发现NSManagedObject参考说明:
如果实例化一个托管对象
直接,您必须致电指定
初始化器
(initWithEntity:insertIntoManagedObjectContext :)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。