rspec/rules/S1155/swift/rule.adoc

18 lines
435 B
Plaintext
Raw Normal View History

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