问题描述
我使用coreData,我有一对多的文件夹和文件之间的关系。
我只使用一个MOC通过我的应用程序。我只是将它传递给不同的
viewControllers,执行添加,编辑,删除和保存操作。
我的rootViewController使用NSfetchResultsController,我使用它创建文件夹,保存并显示在我的表上。
保存我这样做
NSError * error;
if(![self.managedObjectContext save:& error]){
//用代码替换此实现,以正确处理错误。
// abort()导致应用程序生成崩溃日志并终止。您不应在运送应用程序中使用此功能,但在开发过程中可能很有用。
NSLog(@未解析的错误%@,%@,错误,[错误userInfo]);
abort();
}
然后每当我选择一个文件夹时,我打开一个文件ViewController,我通过MOC以这种方式文件VC
FileViewController * file = [[FileViewController alloc] initWithNibName:@FileViewController零];
file.managedObjectContext = self.managedObjectContext;
file.controller = self.controller;
然后我在FileVC中创建一个文件并再次保存在FileVC中,这样
NSError * error;
if(![self.managedObjectContext save:& error]){
//用代码替换此实现,以正确处理错误。
// abort()导致应用程序生成崩溃日志并终止。您不应在运送应用程序中使用此功能,但在开发过程中可能很有用。
NSLog(@未解析的错误%@,%@,错误,[错误userInfo]);
abort();
}
这样做,我使用两个MOC或单个MOC? p>
在我的appdelegate.m,我也试过了这个
self.rootViewController = [[RootViewController alloc] initWithNibName:@RootViewControllerbundle:nil];
_navigationController = [[UINavigationController alloc] initWithRootViewController:self.rootViewController];
[self.managedObjectContext setMergePolicy:NSMergeByPropertyStoreTrumpMergePolicy];
self.rootViewController.managedObjectContext = self.managedObjectContext;有时当我在一个文件夹中添加一个文件时,我得到NSMergeConflict for NSManagedObject
请帮助
尊敬
Ranjit。
解决方案我确定你只使用一个管理对象上下文。你必须创建第二个,使用第二个。虽然即使我是对的,我对NSMergeConflict没有评论,因为我现在正在处理自己。
I am working with coreData, I have one to many relationship between folders and files.
I am using only one MOC through out my application.I am just passing it to different
viewControllers , performing operations like add, edit, delete and then saving.
My rootViewController uses NSfetchResultsController, I create folders using it, save and display on my table.
saving I do it this way
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();
}
then whenever I select a folder, I open a file ViewController, while opening, I pass the MOC to file VC this way
FileViewController *file = [[FileViewController alloc] initWithNibName:@"FileViewController" bundle:nil];
file.managedObjectContext = self.managedObjectContext;
file.controller = self.controller;
then I create a file inside FileVC and again save it in FileVC, this way
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();
}
by doing this, am I using two MOC's or a single MOC?
In my appdelegate.m, I also tried this
self.rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
_navigationController = [[UINavigationController alloc] initWithRootViewController:self.rootViewController];
[self.managedObjectContext setMergePolicy:NSMergeByPropertyStoreTrumpMergePolicy];
self.rootViewController.managedObjectContext = self.managedObjectContext;
Sometimes when I add a file inside a folder , I get "NSMergeConflict for NSManagedObject"
Please help
RegardsRanjit.
解决方案 I'm pretty sure you're using only the one managed object context. You'd have to create a second one to be using a second one. Although even if I'm right about that, I have no comment about the NSMergeConflict as I'm dealing with that myself right now.
这篇关于NSMergeConflict用于具有单个ManagedObjectContext的NSManagedObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!