FormatStyle
A type that can convert a given data type into a representation.
- iOS
- 15.0+
- macOS
- 12.0+
- tvOS
- 15.0+
- watchOS
- 8.0+
protocol FormatStyle : Decodable, Encodable, Hashable
Browse conforming typesA type that can convert a given data type into a representation.
protocol FormatStyle : Decodable, Encodable, Hashable
import FoundationEssentials
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Equatable
A type that can be compared for value equality.
associatedtype FormatInput
The type of data to format.
associatedtype FormatOutput
The type of the formatted data.
func format(_ value: Self.FormatInput) -> Self.FormatOutput
Creates a FormatOutput
instance from value
.
func locale(_ locale: Locale) -> Self
If the format allows selecting a locale, returns a copy of this format with the new locale set. Default implementation returns an unmodified self.
func locale(_ locale: Locale) -> Self
protocol DiscreteFormatStyle<FormatInput, FormatOutput> : FormatStyle
A format style that transforms a continuous input into a discrete output and provides information about its discretization boundaries.
protocol ParseableFormatStyle : FormatStyle
A type that can convert a given data type into a representation.
struct ISO8601FormatStyle
Options for generating and parsing string representations of dates following the ISO 8601 standard.
static var iso8601: Date.ISO8601FormatStyle { get }
import FoundationInternationalization
static func currency<Value>(code: String) -> Self where Self == FloatingPointFormatStyle<Value>.Currency, Value : BinaryFloatingPoint
static func currency<V>(code: String) -> Self where Self == IntegerFormatStyle<V>.Currency, V : BinaryInteger
static func list<MemberStyle, Base>(memberStyle: MemberStyle, type: ListFormatStyle<MemberStyle, Base>.ListType, width: ListFormatStyle<MemberStyle, Base>.Width = .standard) -> Self where Self == ListFormatStyle<MemberStyle, Base>, MemberStyle : FormatStyle, Base : Sequence, MemberStyle.FormatInput == Base.Element, MemberStyle.FormatOutput == String
static func list<Base>(type: ListFormatStyle<StringStyle, Base>.ListType, width: ListFormatStyle<StringStyle, Base>.Width = .standard) -> Self where Self == ListFormatStyle<StringStyle, Base>, Base : Sequence, Base.Element == String
struct FormatStyle
Strategies for formatting a Date
.
static var dateTime: Date.FormatStyle { get }
struct IntervalFormatStyle
static var interval: Date.IntervalFormatStyle { get }
struct RelativeFormatStyle
static func relative(presentation: Date.RelativeFormatStyle.Presentation, unitsStyle: Date.RelativeFormatStyle.UnitsStyle = .wide) -> Self
struct VerbatimFormatStyle
Formats a Date
using the given format.
static func verbatim(_ format: Date.FormatString, locale: Locale? = nil, timeZone: TimeZone, calendar: Calendar) -> Date.VerbatimFormatStyle
struct FormatStyle
static var number: Decimal.FormatStyle { get }
struct Percent
static var percent: Decimal.FormatStyle.Percent { get }
struct Currency
static func currency(code: String) -> Self
struct IntegerFormatStyle<Value> where Value : BinaryInteger
static var number: IntegerFormatStyle<Int16> { get }
static var number: IntegerFormatStyle<Int32> { get }
static var number: IntegerFormatStyle<Int64> { get }
static var number: IntegerFormatStyle<Int8> { get }
static var number: IntegerFormatStyle<Int> { get }
static var number: IntegerFormatStyle<UInt16> { get }
static var number: IntegerFormatStyle<UInt32> { get }
static var number: IntegerFormatStyle<UInt64> { get }
static var number: IntegerFormatStyle<UInt8> { get }
static var number: IntegerFormatStyle<UInt> { get }
struct Percent
static var percent: IntegerFormatStyle<Int16>.Percent { get }
static var percent: IntegerFormatStyle<Int32>.Percent { get }
static var percent: IntegerFormatStyle<Int64>.Percent { get }
static var percent: IntegerFormatStyle<Int8>.Percent { get }
static var percent: IntegerFormatStyle<Int>.Percent { get }
static var percent: IntegerFormatStyle<UInt16>.Percent { get }
static var percent: IntegerFormatStyle<UInt32>.Percent { get }
static var percent: IntegerFormatStyle<UInt64>.Percent { get }
static var percent: IntegerFormatStyle<UInt8>.Percent { get }
static var percent: IntegerFormatStyle<UInt>.Percent { get }
struct ByteCountFormatStyle
static func byteCount(style: ByteCountFormatStyle.Style, allowedUnits: ByteCountFormatStyle.Units = .all, spellsOutZero: Bool = true, includesActualByteCount: Bool = false) -> Self
struct FloatingPointFormatStyle<Value> where Value : BinaryFloatingPoint
static var number: FloatingPointFormatStyle<Double> { get }
static var number: FloatingPointFormatStyle<Float16> { get }
static var number: FloatingPointFormatStyle<Float> { get }
struct Percent
static var percent: FloatingPointFormatStyle<Double>.Percent { get }
static var percent: FloatingPointFormatStyle<Float16>.Percent { get }
static var percent: FloatingPointFormatStyle<Float>.Percent { get }
struct TimeFormatStyle
Format style to format a Duration
in a localized positional format. For example, one hour and ten minutes is displayed as “1:10:00” in the U.S. English locale, or “1.10.00” in the Finnish locale.
static func time(pattern: Duration.TimeFormatStyle.Pattern) -> Self
A factory variable to create a time format style to format a duration.
struct UnitsFormatStyle
A FormatStyle
that displays a duration as a list of duration units, such as “2 hours, 43 minutes, 26 seconds” in English.
static func units(allowed units: Set<Duration.UnitsFormatStyle.Unit> = [.hours, .minutes, .seconds], width: Duration.UnitsFormatStyle.UnitWidth = .abbreviated, maximumUnitCount: Int? = nil, zeroValueUnits: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy = .hide, valueLength: Int? = nil, fractionalPart: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy = .hide) -> Self
A factory function to create a units format style to format a duration.
static func units<ValueRange>(allowed units: Set<Duration.UnitsFormatStyle.Unit> = [.hours, .minutes, .seconds], width: Duration.UnitsFormatStyle.UnitWidth = .abbreviated, maximumUnitCount: Int? = nil, zeroValueUnits: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy = .hide, valueLengthLimits: ValueRange, fractionalPart: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy = .hide) -> Self where ValueRange : RangeExpression, ValueRange.Bound == Int
A factory function to create a units format style to format a duration.