Instance Method


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


func isEqual(to aString: String) -> Bool



The string with which to compare the receiver.

Return Value

true if aString is equivalent to the receiver (if they have the same id or if they are NSOrderedSame in a literal comparison), otherwise false.


The comparison uses the canonical representation of strings, which for a particular string is the length of the string plus the UTF-16 code units that make up the string. When this method compares two strings, if the individual Unicodes are the same, then the strings are equal, regardless of the backing store. “Literal” when applied to string comparison means that various Unicode decomposition rules are not applied and UTF-16 code units are individually compared. So, for instance, “Ö” represented as the composed character sequence “O” (U+004F LATIN CAPITAL LETTER O) and a combining diaeresis “¨” (U+0308 COMBINING DIAERESIS) would not compare equal to “Ö” represented as a single Unicode character (U+00D6 LATIN CAPITAL LETTER O WITH DIAERESIS).

Special Considerations

When you know both objects are strings, this method is a faster way to check equality than isEqual(_:).

See Also