rspec/rules/S1155/swift/rule.adoc

25 lines
616 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +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) {
/* ... */
}
----
ifdef::env-github,rspecator-view[]
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]