• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - CoreData合并冲突与单个上下文

[复制链接]
菜鸟教程小白 发表于 2022-12-12 23:57:39 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我无法解决一个看起来太愚蠢而无法存在的问题。我有一个使用 CoreData 生成对象的 UITableView。

我在 [context save] 处返回错误:

if (editingStyle == UITableViewCellEditingStyleDelete) {
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];

    Stop *stop=[self.fetchedResultsController objectAtIndexPath:indexPath];

    [context deleteObject:stop];


    NSError *error = nil;
    if (![context save:&error]) {
        // Replace this implementation with code to handle the error appropriately.
        // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);

当我传递停止对象和上下文时(通过对 [self.fetchedResultsController managedObjectContext]; 的新调用返回另一个 View 并像这样保存它:

        Stop *object= [[self fetchedResultsController] objectAtIndexPath:indexPath];
    [[segue destinationViewController] setStopbject];
    [[segue destinationViewController] setContext:[self.fetchedResultsController managedObjectContext]];

-(void)viewWillDisappearBOOL)animated
{
    NSError *error = nil;
    self.stop.locationText=self.textLocationField.text;
    [self.stop.managedObjectContext save:&error];

if (![self.context save:&error]) {
    // Replace this implementation with code to handle the error appropriately.
    // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);

该错误是一个 NSMergeConflict,据我了解,当多个 MOC 对同一数据进行操作时会发生此错误。但我一定错过了一些基本的东西,因为我不相信我有两个上下文。我不是在一个上下文中简单地创建、修改和删除对象吗?



Best Answer-推荐答案


经过大量试验和错误后,当您没有定向关系时,您会遇到 NSMergeConflict。因此,如果您有一个人有脚,那么您的脚必须指向关系图中的一个人。

关于ios - CoreData合并冲突与单个上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24847500/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap