views:

26

answers:

1

Core Data is calling these methods in certain situations:

- (BOOL)validateForInsert:(NSError **)outError;
- (BOOL)validateForUpdate:(NSError **)outError;
- (BOOL)validateForDelete:(NSError **)outError;

I wonder if they're doing anything different, or if they're essentially doing the exact same things.

As far as I know, these methods call the -validateValue:forKey:error: method once for every property.

The only difference I can imagine is in the .validateForDelete: method. I see no reason why to validate an object when it shall be deleted, except for applying delete rules, probably only in the case of the DENY rule.

+1  A: 

These are lifecycle validation methods. There are many situations that the question of validation differs depending on the object's state. For example:

  • Don't delete unless child X is nil
  • Don't insert unless value X is unique
  • Don't update unless child Y has been set

These methods give finer grain control over the integrity of the object hierarchy.

Marcus S. Zarra