NSMergeConflict for NSManagedObject with single ManagedObjectContext

爱⌒轻易说出口 提交于 2019-12-19 11:58:31

问题


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

Regards Ranjit.


回答1:


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.



来源:https://stackoverflow.com/questions/19443853/nsmergeconflict-for-nsmanagedobject-with-single-managedobjectcontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!