Entries Tagged 'CoreData' ↓

iPhone SDK CoreData Debugging Error 1560 & 1570

One of my CoreData applications started acting buggy, and was spitting out a huge error dump on app close in the debug console. The errors spitting out didn't tell me anything but CoreData Error 1560 and 1570. Upon inspection I found on google that another layer of errors is stored in the CoreData foundation. On Stack OverFlow found a very useful function but re-wrote it because

![[survey managedObjectContext] save:&error]

was causing an error.

Add this into you applicationWillTerminate function in your Application Delegate

/**
 applicationWillTerminate: saves changes in the application's managed object context before the application terminates.
 */

- (void)applicationWillTerminate:(UIApplication *)application {
       
        NSError* error;
        if(![[self managedObjectContext] save:&error]) {
                NSLog(@"Failed to save to data store: %@", [error localizedDescription]);
                NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
                if(detailedErrors != nil && [detailedErrors count] > 0) {
                        for(NSError* detailedError in detailedErrors) {
                                NSLog(@"  DetailedError: %@", [detailedError userInfo]);
                        }
                }
                else {
                        NSLog(@"  %@", [error userInfo]);
                }
        }
       
}

The original post can be found here

The cause of Error in my CoreData Application was an Attribute in my xcdatamodel file. An optional field was checked as indexed and not optional. The simple action of unchecking indexed and checking optional fixed a whole mass of errors.
CoreData Error