An abstract class that declares an interface for objects that create, interpret, and validate the textual representation of values.
SDKs
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
class Formatter : NSObject
Overview
The Foundation framework provides several concrete subclasses of Formatter
, including Byte
, Date
, Date
, Date
, Energy
, Length
, Mass
, Number
, and Person
.
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.