Creates a string suitable for comparison by removing the specified character distinctions from a string.
- iOS 2.0+
- macOS 10.5+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
The locale to use for the folding operation. Pass
nilto use the system locale.
A string created by performing a character folding operation with the specified options and locale.
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 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
localized method for each pair of strings, you might first normalize both sets of strings by calling the
string method, passing the
NSCase option and the current locale, and then compare each pair of folded strings using the
Rules for how characters are folded may vary, depending on the locale. For example, when folding a string containing the character "I" (
LATIN CAPITAL LETTER I) and specifying the
NSCase comparison option, an English-speaking locale returns "i" (
LATIN SMALL LETTER I), and a Turkish-speaking locale returns “ı” (
U+0131 LATIN SMALL DOTLESS I).