Avatar ·

How to get string length in Swift? The .length property doesn't work like in Objective-C

Hi everyone! I just started learning Swift, before that I wrote a little in Objective-C. There, to get the length of a string, I simply wrote: ```objc NSString *str = @"Hello"; NSInteger len = [str length]; ``` Now I'm trying to do the same in Swift, but the compiler gives an error. Here's my code: ```swift let str = "Hello" let len = str.length // Error: Value of type 'String' has no member 'length' ``` I tried searching online and found that in Swift you need to use `count`, but I'm not getting it right: ```swift let str = "Hello" let len = str.count // This works, but gives a strange result for emojis ``` The problem is that when I count the length of a string with emojis, for example "👨‍👩‍👧‍👦 Family", `count` returns 1 for this compound emoji, although visually there are 4 people