Instance Method


Compares the string and a given string using a localized comparison.


func localizedCompare(_ string: String) -> ComparisonResult



The string with which to compare the receiver.

This value must not be nil. If this value is nil, the behavior is undefined and may change in future versions of macOS.

Return Value

Returns an ComparisonResult value that indicates the lexical ordering. orderedAscending the receiver precedes aString in lexical ordering, orderedSame the receiver and aString are equivalent in lexical value, and orderedDescending if the receiver follows aString.


This method uses the current locale.

See Also

Related Symbols

func compare(String, options: NSString.CompareOptions = [], range: NSRange, locale: Any?)

Compares the string using the specified options and returns the lexical ordering for the range.