ParsableFormatStyle
Apple’s modern Swift replacement system for
Formatteris a set of protocols:FormatStyleandParseableFormatStyle. The former handles the conversion to strings, and the latter strings to data.[…]
The most direct way of parsing a string into it’s respective data type is to create an instance of a
ParseableFormatStylethat’s set up to understand the structure of the incoming string. From there you access it’sparseStrategyproperty, and call theparse()method on it.This is a bit cumbersome, so Apple has included custom initializers onto each of the supported data types that take the string and either a
ParseableFormatStyleor aParseStrategyinstance to do the parsing. What’s interesting is that Apple includes initializers that can accept any input type, as long as you provide aParseStrategythat informs the type how to parse it. Aren’t constrained generics neat?[…]
New for iOS 16, you can now parse URLs using this exact manner[…]
Previously: