<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/folding(options:locale:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)stringByFoldingWithOptions:locale:"
  },
  "title" : "folding(options:locale:)"
}
-->

# folding(options:locale:)

Creates a string suitable for comparison by removing the specified character distinctions from a string.

```
func folding(options: NSString.CompareOptions = [], locale: Locale?) -> String
```

## Parameters

`options`

Any combination of the  [`caseInsensitive`](/documentation/Foundation/NSString/CompareOptions/caseInsensitive), [`widthInsensitive`](/documentation/Foundation/NSString/CompareOptions/widthInsensitive), and [`diacriticInsensitive`](/documentation/Foundation/NSString/CompareOptions/diacriticInsensitive) comparison options.

`locale`

The locale to use for the folding operation. Pass `nil` to use the system locale.

## Return Value

A string created by performing a character folding operation with the specified options and locale.

## Discussion

When working with text—especially text in Latin script—it’s often useful to compare strings in such a way that ignores differences in case (uppercase or lowercase), width (full-width or half-width), and/or diacritics (accents and other marks).

To accomplish this, you may use one of the methods described in Identifying and Comparing Strings, passing one or more options specified by the [`NSString.CompareOptions`](/documentation/Foundation/NSString/CompareOptions) type as appropriate. If you’re performing many such comparisons, you may instead, as an optimization, perform a single folding operation on the string and store the result, passing that into a more efficient comparison method. For example, if you were determining the case-insensitive (that is, “HELLO”, “hello”, and “Hello” are all considered equal) intersection of two sets of strings, instead of calling the [`localizedCaseInsensitiveCompare(_:)`](/documentation/Foundation/NSString/localizedCaseInsensitiveCompare(_:)) method for each pair of strings, you might first normalize both sets of strings by calling the [`folding(options:locale:)`](/documentation/Foundation/NSString/folding(options:locale:)) method, passing the [`caseInsensitive`](/documentation/Foundation/NSString/CompareOptions/caseInsensitive) option and the current locale, and then compare each pair of folded strings using the [`isEqual(to:)`](/documentation/Foundation/NSString/isEqual(to:)) method.

> Tip:
> Character folding operations using the ``doc://com.apple.foundation/documentation/Foundation/NSString/folding(options:locale:)`` method are often more performant than the equivalent string transform using the ``doc://com.apple.foundation/documentation/Foundation/NSString/applyingTransform(_:reverse:)`` method.

Rules for how characters are folded may vary, depending on the locale. For example, when folding a string containing the character “I” (`U+0049` `LATIN CAPITAL LETTER I`) and specifying the [`caseInsensitive`](/documentation/Foundation/NSString/CompareOptions/caseInsensitive) comparison option, an English-speaking locale returns “i” (`U+0069` `LATIN SMALL LETTER I`), and a Turkish-speaking locale returns “ı” (`U+0131 LATIN SMALL DOTLESS I`).

> Note:
> The result of character folding operations may not be suitable for display to users, and should be used only for internal processing.

---

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)