More FormatStyle
implementation for more types.
Description
This package provides more FormatStyle
implementations for various types. Many types also provide parserStrategy
implementations for parsing strings into the type where appropriate.
It also provides extensions for String and string interpolation to make it easier to format values.
Types
Name |
In (1) |
Out (2) |
Format (3) |
Parser (4) |
Accessor (5) |
Notes |
|
BinaryFloatingPoint |
String |
Angles |
Yes |
angle |
Radians, degrees, etc |
|
BinaryFloatingPoint |
String |
Degree Minute Seconds |
No |
dmsNotation |
|
|
CGPoint |
String |
List (6) |
Yes |
point |
|
|
ClosedRange |
String |
X ... Y |
Yes |
No |
|
|
CLLocationCoordinate2D |
String |
List |
No |
coordinates |
|
|
BinaryFloatingPoint |
String |
Latitude |
No |
latitude |
Including hemisphere |
|
BinaryFloatingPoint |
String |
Longitude |
No |
longitude |
Including hemisphere |
|
Any |
String |
Description |
No |
describing |
Uses String(describing:) |
|
Any |
String |
Dump |
No |
dumped |
Uses dump() |
|
DataProtocol |
String |
Hex-dumped |
No |
hexdumped |
|
|
Codable |
String |
JSON |
Yes |
json |
Uses JSONEncoder and JSONDecoder |
|
SIMD3<Float> |
String |
List or mapping |
Yes |
vector |
|
|
SIMD matrix types |
String |
List |
Yes |
matrix |
|
|
BinaryInteger |
String |
Radixed format |
No |
Various |
Binary, Octal, Hex representations |
Notes
1: Type provided as FormatInput
in the FormatStyle
implementation.
2: Type provided as FormatOutput
in the FormatStyle
implementation.
3: Format of the output.
4: Whether the FormatStyle
implementation provides a corresponding ParserStrategy
.
5: Whether a convenience property is provided to access style on FormatStyle
.
6: Formats the input as a comma-separated list.
Examples
String interpolation
let number = 123.456
let formatted = "The number is \(number, .number)"
// formatted == "The number is 123.456"
CoreGraphics
let point = CGPoint(x: 1.234, y: 5.678)
let formatted = point.formatted(.decimal(places: 2))
// formatted == "(1.23, 5.68)"
Future Plans
The initial priority is to expose formats and parsers for more SIMD/CG types. Some common helper format styles will be added (e.g. “field” parser - see TODO).
TODOs
Resources
Apple
Other
SwiftFormats
More
FormatStyle
implementation for more types.Description
This package provides more
FormatStyle
implementations for various types. Many types also provideparserStrategy
implementations for parsing strings into the type where appropriate.It also provides extensions for String and string interpolation to make it easier to format values.
Types
BinaryFloatingPoint
String
angle
BinaryFloatingPoint
String
dmsNotation
CGPoint
String
point
ClosedRange
String
X ... Y
CLLocationCoordinate2D
String
coordinates
BinaryFloatingPoint
String
latitude
BinaryFloatingPoint
String
longitude
Any
String
describing
String(describing:)
Any
String
dumped
dump()
DataProtocol
String
hexdumped
Codable
String
json
JSONEncoder
andJSONDecoder
SIMD3<Float>
String
vector
String
matrix
BinaryInteger
String
Notes
1: Type provided as
FormatInput
in theFormatStyle
implementation. 2: Type provided asFormatOutput
in theFormatStyle
implementation. 3: Format of the output. 4: Whether theFormatStyle
implementation provides a correspondingParserStrategy
. 5: Whether a convenience property is provided to access style onFormatStyle
. 6: Formats the input as a comma-separated list.Examples
String interpolation
CoreGraphics
Future Plans
The initial priority is to expose formats and parsers for more SIMD/CG types. Some common helper format styles will be added (e.g. “field” parser - see TODO).
TODOs
.formatted()
and.formatted(_ style:)
functions where appropriate.formatted()
exist?)FormatOutput
typesx: 1.234, y: 5.678
(use for SIMD and other CG types)Measurement<Angle>
has no parser we can base it off.Resources
Apple
Other