rspec/rules/S1155/swift/rule.adoc

26 lines
620 B
Plaintext

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)++``.
== Noncompliant Code Example
----
if (arr.count == 0) { // Noncompliant
/* ... */
}
----
== Compliant Solution
----
if (arr.isEmpty) {
/* ... */
}
----
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]