beaudrykock
beaudrykock

Reputation: 248

Core Data NSValidation error 1620

I'm getting a "failed to save" error, no. 1620, when I try the following:

NSManagedObjectContext *context = [self managedObjectContext];

CustomObject *objToInsert = [NSEntityDescription insertNewObjectForEntityForName:@"CustomObject" inManagedObjectContext:context];

objToInsert.variable1 = [NSNumber numberWithFloat:10.0];
objToInsert.variable2 = [NSDate date];
objToInsert.variable3 = [NSNumber numberWithInt:1];

NSError *error;
if (![context save:&error]) {
    NSLog(@"failed to save with error = %@", [error localizedDescription]);
}

This same logic works just fine when saving other NSManagedObject-subclass objects to the managedObjectContext. The 1620 error is listed as being a "number too small" validation error, but there's clearly nothing wrong with the numbers I'm inputting. The three variables are defined in my data model as Float, Date and Integer 16, though I'm not sure whether that's relevant.

The Core Data stack is all present and correct and as I said, works just fine with other insertion logic. Am I missing something here?

EDIT: turns out from the error output that Core Data is trying to save a completely different NSManagedObject subclass, which I work with earlier in execution but not in this method call. Why would this be?

Upvotes: 1

Views: 995

Answers (1)

beaudrykock
beaudrykock

Reputation: 248

In the end, the solution was partly as suggested by Martin R (see comments) but for a completely different entity. It appears that if a required minimum value is set for any other entity in the data model, and that entity is modified and saved at some prior point, any subsequent saves to other entities will cause an error. This does not seem to be sensible - maybe I'm doing something wrong elsewhere? - but removing the minimum value requirement did solve this particular problem.

Upvotes: 3

Related Questions