``` if myString.count > 0 { // `myString` isn't empty } ``` This code seems pretty reasonable…
Vincent Pradeilles
Visit on X@v_pradeilles36K followers
19,050 views
```
if myString.count > 0 {
// `myString` isn't empty
}
```
This code seems pretty reasonable, doesn't it? 😌
But it actually hides quite a serious issue!
Can you guess what that issue is? 🤨
8 Comments
Comments from the original post on X (Twitter)

@megakoxem
Any examples of situations Where those Two would have different results? Or is this just speed differences?
1 like

@v_pradeilles
Normally is it should be only speed differences.

@denizakya
It is O(n) operation
1 like

@ZGV2ZWxvcGVy
comparing ‘== false’ is slow for the compiler to type check, why wouldn’t you use ‘!myString.isEmpty’?

@SionSasson
@avi_tsadok ☝🏽

@franktinsley
How does isEmpty check if there is at least 1 character?

@hakidu_Roi
Merci frérot

@hozetonoze
why tf is .count not a constant time op
