<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/ParseStrategy",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation13ParseStrategyP"
  },
  "title" : "ParseStrategy"
}
-->

# ParseStrategy

A type that parses an input representation, such as a formatted string, into a provided data type.

```
protocol ParseStrategy : Decodable, Encodable, Hashable
```

## Overview

A [`ParseStrategy`](/documentation/Foundation/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`](/documentation/Foundation/Decimal) from a formatted string with the initializer [`init(_:format:lenient:)`](/documentation/Foundation/Decimal/init(_:format:lenient:)-6fk71).
- Create a parse strategy and call its [`parse(_:)`](/documentation/Foundation/ParseStrategy/parse(_:)) method on one or more formatted instances.

[`ParseStrategy`](/documentation/Foundation/ParseStrategy) is closely related to [`FormatStyle`](/documentation/Foundation/FormatStyle), which provides the opposite conversion: from data type to formatted representation. To use a parse strategy, you create a [`FormatStyle`](/documentation/Foundation/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`](/documentation/Foundation/Decimal/FormatStyle/Currency) format style that uses US dollars and US English number-formatting conventions. It then creates a [`Decimal`](/documentation/Foundation/Decimal) instance by providing a formatted string to parse and the format style’s [`parseStrategy`](/documentation/Foundation/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
```

## Topics

### Performing parsing

[`parse(_:)`](/documentation/Foundation/ParseStrategy/parse(_:))

Parses a value, using this strategy.

### Commonly-used parsers

Use the static accessors in this section to get parse strategies for common input types like dates and URLs.

[`fixed(format:timeZone:locale:)`](/documentation/Foundation/ParseStrategy/fixed(format:timeZone:locale:))

A fixed-format date parse strategy.

[`url`](/documentation/Foundation/ParseStrategy/url)

A parse strategy for URLs.

[`name`](/documentation/Foundation/ParseStrategy/name)

A parse strategy for person name components.

### Commonly-used format styles

[`dateTime`](/documentation/Foundation/ParseStrategy/dateTime)

A default format style for formatting dates.

### Supporting types

[`ParseInput`](/documentation/Foundation/ParseStrategy/ParseInput)

The input type parsed by this strategy.

[`ParseOutput`](/documentation/Foundation/ParseStrategy/ParseOutput)

The output type returned by this strategy.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)