iPhone SDK CoreData Debugging Error 1560 & 1570

147

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



5 comments ↓

If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.

  • Helpful Core Data debugging | Juggleware Developers' Blog says on 03.16.10 at 12:46 am comment #1

    [...] crashes without warning it can be a major headache. Replacing the default error handling code with this more involved approach saved me hours of time debugging. tweetmeme_url = [...]

  • Scott says on 01.04.11 at 2:19 am comment #2

    Thanks for posting this. I’d been trying to debug a save for hours, and your snippet of code here finally gave me enough info to figure out what was going wrong.

  • ardeay says on 10.05.11 at 12:44 pm comment #3

    @Scott Your welcome, glad it could help!

  • Manjit Bedi says on 10.20.11 at 9:18 am comment #4

    Thanks, you just saved me oodles of time with debugging some code.

  • iOS by mcgski - Pearltrees says on 12.26.11 at 12:03 pm comment #5

    [...] */ – ( void ) applicationWillTerminate : ( UIApplication * ) application { applicationWillTerminate: saves changes in the application’s managed object context before the application terminates. NSError * error; /** iPhone SDK CoreData Debugging Error 1560 & 1570 | Design Code Execute [...]

Leave a Comment