在关系字段中插入值

发布于 2024-12-13 16:32:12 字数 908 浏览 0 评论 0原文

我尝试在核心数据实体中插入值,但是当我尝试在关系字段中插入时,它崩溃了

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め七分饶幸 2024-12-20 16:32:12

我解决了!!我只需要插入与类似这样的事情相关的 NSManagedObject

NSManagedObject *reporteManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"Reporte" inManagedObjectContext:self.managedObjectContext];

NSManagedObject *partidaManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"Avance" inManagedObjectContext:self.managedObjectContext];

[partidaManagedObject setValue:reporteManagedObject forKey:@"avanceReporte"];

I solve it!! i just have to insert the NSManagedObject that is related some thing like this

NSManagedObject *reporteManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"Reporte" inManagedObjectContext:self.managedObjectContext];

NSManagedObject *partidaManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"Avance" inManagedObjectContext:self.managedObjectContext];

[partidaManagedObject setValue:reporteManagedObject forKey:@"avanceReporte"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文