// Bad
"".count == 0
[Int]().count == 0
[String: String]().count == 0
// Good
"".isEmpty
[Int]().isEmpty
[String: String]().isEmpty
<理由>
公式リファレンスにて、.isEmpry
の使用が推奨されています。
.count
の取得は、計算量がO(n)となる場合があるから、だそうです。
<補足>
SwiftLintにおいては、.count
との比較と同様にリテラルとの比較も警告対象となります。
// Bad
myString == ""
myArray == []
myDict == [:]