SLN SLN - 6 months ago 35
Swift Question

What's the different between CharacterView and UnicodeScalarView of the String type

The following two code practically did the same thing

for character in "Dog!


This comes down to the difference between a Character and UnicodeScalar.

Unicode Scalars

Behind the scenes, Swift’s native String type is built from Unicode scalar values. A Unicode scalar is a unique 21-bit number for a character or modifier, such as U+0061 for LATIN SMALL LETTER A ("a"), or U+1F425 for FRONT-FACING BABY CHICK ("