Troubleshooting

If you have trouble getting your app to work correctly, try the problem-solving approaches described in this chapter.

Diagnosing Object ID Issues

If you log a managed object ID or the object ID’s URIRepresentation object and you get an unrecognized selector exception or it prints <(null)>, check that your reference object is of type NSString or NSNumber. All other types are unsupported.

Diagnosing Faulting Issues

If an NSObjectInaccessibleException exception is raised when accessing the properties on a managed object it could be for one of the following reasons:

If an empty to-one relationship cannot be faulted in, return [NSNull null] rather than nil from newValuesForObjectWithID:withContext:error: or newValueForRelationship:forObjectWithID:withContext:error: to inform the persistent store coordinator that the relationship is empty. Otherwise, the persistent store coordinator assumes that an internal error occurred.

If an empty to-many relationship cannot be faulted in, you are returning nil in one of the two relationship fulfillment methods. Realization of to-many relationships can be deferred until newValueForRelationship:forObjectWithID:withContext:error:. However, when this method is called, the relationship must be fulfilled. If the relationship does not contain any objects, return an empty array rather than nil. Otherwise, the persistent store coordinator assumes that an internal error occurred.

Diagnosing Optimistic Locking Issues

If merge conflicts are not being resolved or the merge policy is failing, check that the following parts of your implementation are correct:

If merge conflicts are erroneously detected, ensure that you are incrementing version numbers every time records are saved.