gpt4 book ai didi

ios - 具有单个 ManagedObjectContext 的 NSManagedObject 的 NSMergeConflict

转载 作者:行者123 更新时间:2023-11-29 03:33:45 26 4
gpt4 key购买 nike

我正在使用 coreData,文件夹和文件之间有一对多的关系。

我在整个应用程序中仅使用一个 MOC。我只是将其传递给不同的

viewControllers,执行添加、编辑、删除和保存等操作。

我的rootViewController使用NSfetchResultsController,我使用它创建文件夹,保存并显示在我的 table 上。

保存我就是这样做的

        NSError *error;
if (![self.managedObjectContext 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]);
abort();
}

然后每当我选择一个文件夹时,我都会打开一个文件ViewController,在打开时,我通过这种方式将MOC传递给文件VC

         FileViewController *file = [[FileViewController alloc] initWithNibName:@"FileViewController" bundle:nil];

file.managedObjectContext = self.managedObjectContext;
file.controller = self.controller;

然后我在 FileVC 中创建一个文件,并再次将其保存在 FileVC 中,这样

        NSError *error;
if (![self.managedObjectContext 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]);
abort();
}

通过这样做,我使用的是两个 MOC 还是单个 MOC?

在我的appdelegate.m中,我也尝试过这个

self.rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];

_navigationController = [[UINavigationController alloc] initWithRootViewController:self.rootViewController];
[self.managedObjectContext setMergePolicy:NSMergeByPropertyStoreTrumpMergePolicy];

self.rootViewController.managedObjectContext = self.managedObjectContext;

有时,当我在文件夹中添加文件时,我会收到“NSMergeConflict for NSManagedObject”

请帮忙

问候兰 git 。

最佳答案

我很确定您只使用了一个托管对象上下文。您必须创建第二个才能使用第二个。虽然即使我对此是正确的,但我对 NSMergeConflict 没有任何评论,因为我现在正在处理它。

关于ios - 具有单个 ManagedObjectContext 的 NSManagedObject 的 NSMergeConflict,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19443853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com