rspec/rules/S1155/swift/rule.adoc

18 lines
489 B
Plaintext
Raw Normal View History

2020-06-30 12:47:33 +02:00
Using <code>[Int]().count</code> to test for emptiness works, but using <code>[Int]().isEmpty</code> makes the code more readable and can be more performant. The time complexity of any <code>isEmpty</code> implementation should be <code>O(1)</code> whereas some implementations of <code>count()</code> can be <code>O(n)</code>.
== Noncompliant Code Example
----
if (arr.count == 0) { // Noncompliant
/* ... */
}
----
== Compliant Solution
----
if (arr.isEmpty) {
/* ... */
}
----