NSMergeConflict dla NSManagedObject z pojedynczym ManagedObjectContext

Pracuję z coreData, mam relację jeden do wielu między folderami i plikami.

Korzystam tylko z jednego MOC poprzez moją aplikację. Po prostu przekazuję to do innego

viewControllers, wykonując operacje takie jak dodawanie, edycja, usuwanie, a następnie zapisywanie.

Mój rootViewController używa NSfetchResultsController, tworzę foldery, zapisuję i wyświetlaję na moim stole.

oszczędność Robię to w ten sposób

        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();
        }

wtedy, gdy wybieram folder, otwieram plik ViewController, otwierając, przekazuję MOC do pliku VC w ten sposób

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

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

następnie tworzę plik w FileVC i ponownie zapisuję go w FileVC, w ten sposób

        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();
        }

robiąc to, czy używam dwóch MOC lub pojedynczego MOC?

W moim appdelegate.m próbowałem również tego

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

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

            self.rootViewController.managedObjectContext = self.managedObjectContext;

Czasami, gdy dodaję plik do folderu, otrzymuję „NSMergeConflict for NSManagedObject”

Proszę pomóż

Pozdrawiam Ranjit.

questionAnswers(1)

yourAnswerToTheQuestion