Instance Method


Returns the result of invoking compare(_:options:range:locale:) with a nil locale.


func compare(_ string: String, options mask: NSString.CompareOptions = [], range rangeOfReceiverToCompare: NSRange) -> ComparisonResult



The string with which to compare the range of the receiver specified by range.

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


Options for the search—you can combine any of the following using a C bitwise OR operator: NSCaseInsensitiveSearch, NSLiteralSearch, NSNumericSearch.

See String Programming Guide for details on these options.


The range of the receiver over which to perform the comparison. The range must not exceed the bounds of the receiver.

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 is equivalent to invoking compare(_:options:range:locale:) with a nil locale.

See Also

Related Symbols

func isEqual(to: String)

Returns a Boolean value that indicates whether a given string is equal to the receiver using a literal Unicode-based comparison.

func localizedStandardCompare(String)

Compares strings as sorted by the Finder.

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.