Contents

Data Formatting

Convert numbers, dates, measurements, and other values to and from locale-aware string representations.

Overview

Foundation supports two approaches for data formatting:

  • When working in Swift, use formatted methods directly on the types you want to format, optionally using FormatStyle and its subtypes to customize formatter output. This approach supports dates, integers, floating-point numbers, measurements, sequences, and person name components. Foundation caches identically-configured formatter instances internally, allowing you to focus on your app’s formatting needs.

  • In Objective-C, create instances of Formatter and its subtypes, and use the string(for:) method to convert objects to formatted strings.

Topics

Essentials

Data formatting in Swift

Data parsing in Swift

Numbers and currency

Names

Dates and times

Data sizes

Measurements

Lists

Internationalization

Custom formatters

Automatic grammar agreement

Deprecated

See Also

Fundamentals