Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm throwing this in as an answer, even though it's really more of an embellishment to Charles' snippet. The straight output from NSLog can be a mess to read and interpret, so I like to throw in some white space and call out the value of some critical 'userInfo' keys.</p> <p>Here's a version of the method I've been using. ('_sharedManagedObjectContext' is a #define for '[[[UIApplication sharedApplication] delegate] managedObjectContext]'.)</p> <pre><code>- (BOOL)saveData { NSError *error; if (![_sharedManagedObjectContext save:&amp;error]) { // If Cocoa generated the error... if ([[error domain] isEqualToString:@"NSCocoaErrorDomain"]) { // ...check whether there's an NSDetailedErrors array NSDictionary *userInfo = [error userInfo]; if ([userInfo valueForKey:@"NSDetailedErrors"] != nil) { // ...and loop through the array, if so. NSArray *errors = [userInfo valueForKey:@"NSDetailedErrors"]; for (NSError *anError in errors) { NSDictionary *subUserInfo = [anError userInfo]; subUserInfo = [anError userInfo]; // Granted, this indents the NSValidation keys rather a lot // ...but it's a small loss to keep the code more readable. NSLog(@"Core Data Save Error\n\n \ NSValidationErrorKey\n%@\n\n \ NSValidationErrorPredicate\n%@\n\n \ NSValidationErrorObject\n%@\n\n \ NSLocalizedDescription\n%@", [subUserInfo valueForKey:@"NSValidationErrorKey"], [subUserInfo valueForKey:@"NSValidationErrorPredicate"], [subUserInfo valueForKey:@"NSValidationErrorObject"], [subUserInfo valueForKey:@"NSLocalizedDescription"]); } } // If there was no NSDetailedErrors array, print values directly // from the top-level userInfo object. (Hint: all of these keys // will have null values when you've got multiple errors sitting // behind the NSDetailedErrors key. else { NSLog(@"Core Data Save Error\n\n \ NSValidationErrorKey\n%@\n\n \ NSValidationErrorPredicate\n%@\n\n \ NSValidationErrorObject\n%@\n\n \ NSLocalizedDescription\n%@", [userInfo valueForKey:@"NSValidationErrorKey"], [userInfo valueForKey:@"NSValidationErrorPredicate"], [userInfo valueForKey:@"NSValidationErrorObject"], [userInfo valueForKey:@"NSLocalizedDescription"]); } } // Handle mine--or 3rd party-generated--errors else { NSLog(@"Custom Error: %@", [error localizedDescription]); } return NO; } return YES; } </code></pre> <p>This allows me to see the value for 'NSValidationErrorKey', which, when I encountered the issue from the OP, pointed directly to the non-optional Core Data entities that I'd forgot to set before trying to save.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload