Back to questions
JuniorTheoryCommon
What does the program print?
let word = "résumé"
print(word.count, word.utf8.count)6 8
- Expecting
6 6: treatingéas one byte like a Latin letter. In UTF-8 it takes two bytes, so the twoéadd two extra bytes toutf8.count. - Expecting
8 8: thinkingcountcounts bytes, as string length does in some languages. In Swiftcountcounts characters, and bytes are counted byutf8.count.
- What do
countandutf8.countgive for the emoji👍🏽, and why? - Why does Swift have to walk the whole string to find its
count?