Instance Method


Validates a property value for a given key.


- (BOOL)validateValue:(id  _Nullable *)value forKey:(NSString *)key error:(NSError * _Nullable *)error;



A pointer to an object.


The name of one of the receiver's properties.


If value is not a valid value for key (and cannot be coerced), upon return contains an instance of NSError that describes the problem.

Return Value

YES if value is a valid value for key (or if value can be coerced into a valid value for key), otherwise NO.


This method is responsible for two things: coercing the value into an appropriate type for the object, and validating it according to the object’s rules.

The default implementation provided by NSManagedObject consults the object’s entity description to coerce the value and to check for basic errors, such as a null value when that isn’t allowed and the length of strings when a field width is specified for the attribute. It then searches for a method of the form validate<Key>:error: and invokes it if it exists.

You can implement methods of the form validate<Key>:error: to perform validation that is not possible using the constraints available in the property description. If it finds an unacceptable value, your validation method should return NO and in error an NSError object that describes the problem. For more details, see Managed Object Validation. For inter-property validation (to check for combinations of values that are invalid), see validateForUpdate: and related methods.

See Also

Managing Data Validation

- validateForDelete:

Determines whether the managed object can be deleted in its current state.

- validateForInsert:

Determines whether the managed object can be inserted in its current state.

- validateForUpdate:

Determines whether the managed object's current state is valid.

Validation Error Codes

Error codes related to validation of managed object properties.


The error key for the attribute that failed to validate.


The error key for the object that failed to validate.


The error key for the predicate that failed to validate.


The error key for the value that failed to validate.