35 lines
744 B
Plaintext
35 lines
744 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
|
|
|
|
[source,swift]
|
|
----
|
|
if (arr.count == 0) { // Noncompliant
|
|
/* ... */
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
[source,swift]
|
|
----
|
|
if (arr.isEmpty) {
|
|
/* ... */
|
|
}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|