<!--
{
  "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/IntegerParseStrategy",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation20IntegerParseStrategyV"
  },
  "title" : "IntegerParseStrategy"
}
-->

# IntegerParseStrategy

A parse strategy for creating integer values from formatted strings.

```
struct IntegerParseStrategy<Format> where Format : FormatStyle, Format.FormatInput : BinaryInteger
```

## Overview

Create an explicit [`IntegerParseStrategy`](/documentation/Foundation/IntegerParseStrategy) to parse multiple strings according to the same parse strategy. In the following example, `usCurrencyStrategy` is an [`IntegerParseStrategy`](/documentation/Foundation/IntegerParseStrategy) that uses US dollars and the `en_US` locale’s conventions for number formatting. The example then uses this strategy to parse an array of strings, some of which represent valid US currency values.

```swift
let usCurrencyStrategy: IntegerParseStrategy =
    IntegerFormatStyle<Int>.Currency(code: "USD",
                                     locale: Locale(identifier: "en_US"))
    .parseStrategy
let currencyValues = ["$100", "$1,000", "$10,000", "€100"]
let parsedValues = currencyValues.map { try? usCurrencyStrategy.parse($0) } // [Optional(100), Optional(1000), Optional(10000), nil]
```

You don’t need to instantiate a parse strategy variable to parse a single string. Instead, use the <doc://com.apple.documentation/documentation/Swift/BinaryInteger> initializers that take a source <doc://com.apple.documentation/documentation/Swift/String> and a `format` parameter to parse the string according to the provided [`FormatStyle`](/documentation/Foundation/FormatStyle). The following example parses a string that represents a currency value in US dollars.

```swift
let formattedUSDollars = "$1,234"
let parsedUSDollars = try? Int(formattedUSDollars, format: .currency(code: "USD")
    .locale(Locale(identifier: "en_US"))) // 1234
```

## Topics

### Creating an integer parse strategy

[`init<Value>(format: Format, lenient: Bool)`](/documentation/Foundation/IntegerParseStrategy/init(format:lenient:)-124xn)

Creates a parse strategy instance using the specified integer format style.

[`init<Value>(format: Format, lenient: Bool)`](/documentation/Foundation/IntegerParseStrategy/init(format:lenient:)-7tox3)

Creates a parse strategy instance using the specified integer currency format style.

[`init<Value>(format: Format, lenient: Bool)`](/documentation/Foundation/IntegerParseStrategy/init(format:lenient:)-3gbvo)

Creates a parse strategy instance using the specified integer percentage format style.

### Parsing strings

[`func parse(String) throws -> Format.FormatInput`](/documentation/Foundation/IntegerParseStrategy/parse(_:))

Parses an integer string in accordance with this strategy and returns the parsed value.

### Accessing strategy properties

[`var formatStyle: Format`](/documentation/Foundation/IntegerParseStrategy/formatStyle)

The format style this strategy uses when parsing strings.

[`var lenient: Bool`](/documentation/Foundation/IntegerParseStrategy/lenient)

A Boolean value that indicates whether parsing allows any discrepencies in the expected format.

### Applying date-parsing strategies

### Supporting types

### Default Implementations

[ParseStrategy Implementations](/documentation/Foundation/IntegerParseStrategy/ParseStrategy-Implementations)

## Relationships

### Conforms To

[`Copyable`](/documentation/Swift/Copyable)

[`Equatable`](/documentation/Swift/Equatable)

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

[`Hashable`](/documentation/Swift/Hashable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Decodable`](/documentation/Swift/Decodable)

[`Escapable`](/documentation/Swift/Escapable)

[`Encodable`](/documentation/Swift/Encodable)

[`Sendable`](/documentation/Swift/Sendable)

---

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)