Swift’s strings are unicode-compatible in the best way, counting the real displayed graphemes as the user would see them.
We need to be careful though when working with NSString
APIs, because they deal with unicode differently. In the example below, print((word as NSString).length)
would print 5
, not 4
. So be careful not to apply ranges returned from NSString
-based APIs to String
instances.