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
formattedmethods 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
Language IntrospectorFormatStyleIntegerFormatStyleFloatingPointFormatStyleDecimal.FormatStyleListFormatStyleStringStyleURL.FormatStyleFormatStyleCapitalizationContextFormat Style Configurations
Data parsing in Swift
ParseableFormatStyleParseStrategyIntegerParseStrategyFloatingPointParseStrategyDecimal.ParseStrategy
Numbers and currency
Names
Dates and times
DateFormatterDateComponentsFormatterRelativeDateTimeFormatterDateIntervalFormatterISO8601DateFormatter