Compares the string with the specified string using the given options.
SDKs
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
func compare(_ string: String, options mask: NSString.Compare Options = []) -> Comparison Result
Parameters
aStringThe string with which to compare the receiver.
This value must not be
nil. If this value isnil, the behavior is undefined and may change in future versions of macOS.maskOptions for the search—you can combine any of the following using a C bitwise OR operator:
case,Insensitive literal,numeric. See String Programming Guide for details on these options.
Return Value
Returns an Comparison value that indicates the lexical ordering. Comparison the receiver precedes a in lexical ordering, Comparison the receiver and a are equivalent in lexical value, and Comparison if the receiver follows a.
Discussion
This method is equivalent to invoking compare(_: with a given mask as the options and the receiver’s full extent as the range.
Important
When working with text that’s presented to the user, use the localized instead, or use the compare(_: method, passing the user’s locale.