---
title: Formatter
framework: foundation
role: symbol
role_heading: Class
path: foundation/formatter
---

# Formatter

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

## Declaration

```swift
class Formatter
```

## Overview

Overview The Foundation framework provides several concrete subclasses of Formatter, including ByteCountFormatter, DateFormatter, DateComponentsFormatter, DateIntervalFormatter, MeasurementFormatter, NumberFormatter, and PersonNameComponentsFormatter. tip: In Swift, you can use implementations of FormatStyle rather than Formatter. The FormatStyle API offers a declarative idiom for customizing the formatting of various types. Also, Foundation caches identical FormatStyle instances, so you don’t need to pass them around your app, or risk wasting memory with duplicate formatters. Subclassing Notes Formatter 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.

## Topics

### Creating Formatters

- [Displaying Human-Friendly Content](foundation/displaying-human-friendly-content.md)

### Getting Textual Representations of Object Values

- [string(for:)](foundation/formatter/string(for:).md)
- [attributedString(for:withDefaultAttributes:)](foundation/formatter/attributedstring(for:withdefaultattributes:).md)
- [editingString(for:)](foundation/formatter/editingstring(for:).md)

### Getting Object Values for Textual Representations

- [getObjectValue(_:for:errorDescription:)](foundation/formatter/getobjectvalue(_:for:errordescription:).md)

### Validating Partial Strings

- [isPartialStringValid(_:newEditingString:errorDescription:)](foundation/formatter/ispartialstringvalid(_:neweditingstring:errordescription:).md)
- [isPartialStringValid(_:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:)](foundation/formatter/ispartialstringvalid(_:proposedselectedrange:originalstring:originalselectedrange:errordescription:).md)

### Constants

- [Formatter.Context](foundation/formatter/context.md)
- [Formatter.UnitStyle](foundation/formatter/unitstyle.md)

### Initializers

- [init(coder:)](foundation/formatter/init(coder:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [ByteCountFormatter](foundation/bytecountformatter.md)
- [DateComponentsFormatter](foundation/datecomponentsformatter.md)
- [DateFormatter](foundation/dateformatter.md)
- [DateIntervalFormatter](foundation/dateintervalformatter.md)
- [EnergyFormatter](foundation/energyformatter.md)
- [ISO8601DateFormatter](foundation/iso8601dateformatter.md)
- [LengthFormatter](foundation/lengthformatter.md)
- [ListFormatter](foundation/listformatter.md)
- [MassFormatter](foundation/massformatter.md)
- [MeasurementFormatter](foundation/measurementformatter.md)
- [NumberFormatter](foundation/numberformatter.md)
- [PersonNameComponentsFormatter](foundation/personnamecomponentsformatter.md)
- [RelativeDateTimeFormatter](foundation/relativedatetimeformatter.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
