为更多类型提供更多 FormatStyle
实现。
此包为各种类型提供了更多 FormatStyle
实现。许多类型还提供了 parserStrategy
实现,以便在适当的情况下将字符串解析为该类型。
它还为 String 和字符串插值提供了扩展,以便更轻松地格式化值。
名称 | 输入 (1) | 输出 (2) | 格式 (3) | 解析器 (4) | 访问器 (5) | 注释 |
---|---|---|---|---|---|---|
BinaryFloatingPoint |
String |
角度 | 是 | angle |
弧度、度等 | |
BinaryFloatingPoint |
String |
度分秒 | 否 | dmsNotation |
||
CGPoint |
String |
列表 (6) | 是 | point |
||
ClosedRange |
String |
X ... Y |
是 | 否 | ||
CLLocationCoordinate2D |
String |
列表 | 否 | coordinates |
||
BinaryFloatingPoint |
String |
纬度 | 否 | latitude |
包括半球 | |
BinaryFloatingPoint |
String |
经度 | 否 | longitude |
包括半球 | |
Any |
String |
描述 | 否 | describing |
使用 String(describing:) |
|
Any |
String |
Dump | 否 | dumped |
使用 dump() |
|
DataProtocol |
String |
Hex-dumped | 否 | hexdumped |
||
Codable |
String |
JSON | 是 | json |
使用 JSONEncoder 和 JSONDecoder |
|
SIMD3<Float> |
String |
列表或映射 | 是 | vector |
||
SIMD 矩阵类型 | String |
列表 | 是 | matrix |
||
BinaryInteger |
String |
Radixed 格式 | 否 | 各种 | 二进制、八进制、十六进制表示 |
1:在 FormatStyle
实现中作为 FormatInput
提供的类型。2:在 FormatStyle
实现中作为 FormatOutput
提供的类型。3:输出的格式。4:FormatStyle
实现是否提供相应的 ParserStrategy
。5:是否提供了方便的属性来访问 FormatStyle
上的样式。6:将输入格式化为逗号分隔的列表。
let number = 123.456
let formatted = "The number is \(number, .number)"
// formatted == "The number is 123.456"
let point = CGPoint(x: 1.234, y: 5.678)
let formatted = point.formatted(.decimal(places: 2))
// formatted == "(1.23, 5.68)"
最初的优先级是为更多 SIMD/CG 类型公开格式和解析器。将添加一些常见的辅助格式样式(例如,“field”解析器 - 参见 TODO)。
.formatted()
和 .formatted(_ style:)
函数.formatted()
等效的标准库?)FormatOutput
类型x: 1.234, y: 5.678
(用于 SIMD 和其他 CG 类型)Measurement<Angle>
没有我们可以依赖的解析器。