Validates a property value for a given key.
- iOS 3.0+
- macOS 10.4+
- tvOS 9.0+
- watchOS 2.0+
- Mac Catalyst 13.0+Beta
- Core Data
A pointer to an object.
The name of one of the receiver's properties.
valueis not a valid value for
key(and cannot be coerced), upon return contains an instance of
NSErrorthat describes the problem.
value is a valid value for
key (or if
value can be coerced into a valid value for
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
NSManaged 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>: and invokes it if it exists.
You can implement methods of the form
validate<Key>: 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
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
validate and related methods.