isPartialStringValid(_:newEditingString:errorDescription:)
Returns a Boolean value that indicates whether a partial string is valid.
Declaration
func isPartialStringValid(_ partialString: String, newEditingString newString: AutoreleasingUnsafeMutablePointer<NSString?>?, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> BoolParameters
- partialString:
The text currently in a cell.
- newString:
If
partialStringneeds to be modified, upon return contains the replacement string. - error:
If non-
nil, if validation fails contains anNSStringobject that describes the problem.
Return Value
true if partialString is an acceptable value, otherwise false.
Discussion
This method is invoked each time the user presses a key while the cell has the keyboard focus—it lets you verify and edit the cell text as the user types it.
In a subclass implementation, evaluate partialString according to the context, edit the text if necessary, and return by reference any edited string in newString. Return true if partialString is acceptable and false if partialString is unacceptable. If you return false and newString is nil, the cell displays partialString minus the last character typed. If you return false, you can also return by indirection an NSString object (in error) that explains the reason why the validation failed; the delegate (if any) of the NSControl object managing the cell can then respond to the failure in control:didFailToValidatePartialString:errorDescription:. The selection range will always be set to the end of the text if replacement occurs.
This method is a compatibility method. If a subclass overrides this method and does not override isPartialStringValid(_:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:), this method will be called as before (isPartialStringValid(_:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:) just calls this one by default).