如何为子类 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]);
}
}
I am wondering what the correct way is to create my own initializer of a class that is subclassing NSManagedObject.
Currently I am initializing like this:
-(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]);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚发现 NSManagedObject 参考 说:
Just found that the NSManagedObject reference says: