ParseStrategy
protocol · iOS 15.0+ · SDK 27.1
protocol ParseStrategy : Decodable, Encodable, HashableA type that parses an input representation, such as a formatted string, into a provided data type. A ``ParseStrategy`` allows you to convert a formatted representation into a data type, using one of two approaches: - Initialize the data type by calling an initializer of that type that takes a formatted instance and a parse strategy as parameters. For example, you can create a ``Decimal`` from a formatted string with the initializer ``Decimal/init(_:format:lenient:)-6fk71``. - Create a parse strategy and call its ``parse(_:)`` method on one or more formatted instances. ``ParseStrategy`` is closely related to ``FormatStyle``, which provides the opposite conversion: from data type to formatted representation. To use a parse strategy, you create a ``FormatStyle`` to define the representation you expect, then access the style's `parseStrategy` property to get a strategy instance. The following example creates a ``Decimal/FormatStyle/Currency`` format style that uses US dollars and US English number-formatting conventions. It then creates a ``Decimal`` instance by providing a formatted string to parse and the format style's ``Decimal/FormatStyle/Currency/parseStrategy``. ```swift let style = Decimal.FormatStyle.Currency(code: "USD", locale: Locale(identifier: "en_US")) let parsed = try? Decimal("$12,345.67", strategy: style.parseStrategy) // 12345.67 ```
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
8 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
ParseStrategy.http
Static protocol requirements cannot be called through an instance.
ParseStrategy.http
Static protocol requirements cannot be called through an instance.
ParseStrategy.iso8601
Static protocol requirements cannot be called through an instance.
ParseStrategy.iso8601
Static protocol requirements cannot be called through an instance.
ParseStrategy.url
Static protocol requirements cannot be called through an instance.
ParseStrategy.dateTime
Static protocol requirements cannot be called through an instance.
ParseStrategy.fixed(format:timeZone:locale:)
This protocol needs associated types that cannot yet cross the bridge.
ParseStrategy.name
Static protocol requirements cannot be called through an instance.