在关系字段中插入值
我尝试在核心数据实体中插入值,但是当我尝试在关系字段中插入时,它崩溃了
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName: [entity name] inManagedObjectContext:context];
[newManagedObject setValue:[NSDate date] forKey:@"fechaAprovacion"];
[newManagedObject setValue:[NSDate date] forKey:@"fechaUltimoOficio"];
//relationship field----->[newManagedObject setValue:[NSNumber numberWithInteger:self.index.row] forKey:@"vObra"]; //<---relationship field
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
Im trying to insert values in a core data entity, but when I try to insert in a Relationship field it crash
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName: [entity name] inManagedObjectContext:context];
[newManagedObject setValue:[NSDate date] forKey:@"fechaAprovacion"];
[newManagedObject setValue:[NSDate date] forKey:@"fechaUltimoOficio"];
//relationship field----->[newManagedObject setValue:[NSNumber numberWithInteger:self.index.row] forKey:@"vObra"]; //<---relationship field
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了!!我只需要插入与类似这样的事情相关的 NSManagedObject
I solve it!! i just have to insert the NSManagedObject that is related some thing like this