Search code examples
iphoneobjective-ccocoa-touchipadcore-data

How to debug a CoreData crash on save?


I'm trying to save my object with Coredata in my app but I'm getting a crash and this very confusing error:

Unresolved error Error Domain=NSCocoaErrorDomain Code=1570 "The operation couldn’t be completed. (Cocoa error 1570.)" UserInfo=0x2f8820 {NSValidationErrorObject=<ContactInfo: 0xf081140> (entity: ContactInfo; id: 0x20c0f0 <x-coredata:///ContactInfo/tDCD050E6-3BA3-47D2-A5ED-A22D53749E4B7> ; data: {
    addressLine1 = nil;
    addressLine2 = nil;
    email = nil;
    mobileNo = nil;
    name = nil;
    phoneNo = nil;
    stateCounty = nil;
    townCity = nil;
    venue = nil;
    zipIp = nil;
}), NSValidationErrorKey=name, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1570.)}, {
    NSLocalizedDescription = "The operation couldn\U2019t be completed. (Cocoa error 1570.)";
    NSValidationErrorKey = name;
    NSValidationErrorObject = "<ContactInfo: 0xf081140> (entity: ContactInfo; id: 0x20c0f0 <x-coredata:///ContactInfo/tDCD050E6-3BA3-47D2-A5ED-A22D53749E4B7> ; data: {\n    addressLine1 = nil;\n    addressLine2 = nil;\n    email = nil;\n    mobileNo = nil;\n    name = nil;\n    phoneNo = nil;\n    stateCounty = nil;\n    townCity = nil;\n    venue = nil;\n    zipIp = nil;\n})";
}

ContactInfo is an entity in my core data model, I have another entity called VenueInfo and each of these objects has a ContactInfo object as each venue needs contacts details. I'll add some code and more details if the error message isn't enough.


Solution

  • Turns out this key little bit of info:

    NSValidationErrorKey=name

    Means for the attribute name, theres a validation issue, this was because, not to my knowledge until now, this attribute in my core data model was not optional and as shown is returning nil causing a crash.

    Avoid the crash by either giving the name a value or making it optional.