A closed range that forms a collection of consecutive values.

SDK

Xcode 8.0+

Framework

Swift Standard Library

Overview

You create a CountableClosedRange instance by using the closed range operator (...).

A CountableClosedRange instance contains both its lower bound and its upper bound.

Because a closed range includes its upper bound, a closed range whose lower bound is equal to the upper bound contains one element. Therefore, a CountableClosedRange instance cannot represent an empty range.

You can use a for-in loop or any sequence or collection method with a countable range. The elements of the range are the consecutive values from its lower bound up to, and including, its upper bound.

You can create a countable range over any type that conforms to the Strideable protocol and uses an integer as its associated Stride type. By default, Swift’s integer and pointer types are usable as the bounds of a countable range.

Because floating-point types such as Float and Double are their own Stride types, they cannot be used as the bounds of a countable range. If you need to test whether values are contained within a closed interval bound by floating-point values, see the ClosedRange type. If you need to iterate over consecutive floating-point values, see the stride(from:through:by:) function.

Returns a Boolean value indicating whether this sequence and another sequence contain equivalent elements in the same order, using the given predicate as the equivalence test.

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the less-than operator (<) to compare elements.

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the given predicate to compare elements.

Returns a Boolean value indicating whether the initial elements of the sequence are equivalent to the elements in another sequence, using the given predicate as the equivalence test.