An abstract class that declares an interface for objects that create, interpret, and validate the textual representation of values.


@interface NSFormatter : NSObject


Subclassing Notes

NSFormatter is intended for subclassing. A custom formatter can restrict the input and enhance the display of data in novel ways. For example, you could have a custom formatter that ensures that serial numbers entered by a user conform to predefined formats. Before you decide to create a custom formatter, make sure that you cannot configure the public subclasses to satisfy your requirements.

For instructions on how to create your own custom formatter, see Creating a Custom Formatter.


Getting Textual Representations of Object Values

- stringForObjectValue:

The default implementation of this method raises an exception.

- attributedStringForObjectValue:withDefaultAttributes:

The default implementation returns nil to indicate that the formatter object does not provide an attributed string.

- editingStringForObjectValue:

The default implementation of this method invokes stringForObjectValue:.

Getting Object Values for Textual Representations

- getObjectValue:forString:errorDescription:

The default implementation of this method raises an exception.

Validating Partial Strings

- isPartialStringValid:newEditingString:errorDescription:

Returns a Boolean value that indicates whether a partial string is valid.

- isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:

This method should be implemented in subclasses that want to validate user changes to a string in a field, where the user changes are not necessarily at the end of the string, and preserve the selection (or set a different one, such as selecting the erroneous part of the string the user has typed).



The formatting context for a formatter.


Specifies the width of the unit, determining the textual representation.


Inherits From

Conforms To