StructureSwift5.9.0

    Range

    A half-open interval from a lower bound up to, but not including, an upper bound.

    @frozen struct Range<Bound> where Bound : Comparable

    You create a Range instance by using the half-open range operator (..<).

    let underFive = 0.0..<5.0

    You can use a Range instance to quickly check if a value is contained in a particular range of values. For example:

    underFive.contains(3.14)
    // true
    underFive.contains(6.28)
    // false
    underFive.contains(5.0)
    // false

    Range instances can represent an empty interval, unlike ClosedRange.

    let empty = 0.0..<0.0
    empty.contains(0.0)
    // false
    empty.isEmpty
    // true

    Using a Range as a Collection of Consecutive Values

    When a range uses integers as its lower and upper bounds, or any other type that conforms to the Strideable protocol with an integer stride, you can use that range in a for-in loop or with any sequence or collection method. The elements of the range are the consecutive values from its lower bound up to, but not including, its upper bound.

    for n in 3..<5 {
        print(n)
    }
    // Prints "3"
    // Prints "4"

    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 iterate over consecutive floating-point values, see the stride(from:to:by:) function.

    Citizens in Swift

    Members

    Citizens in Swift

    where Bound:Strideable, Bound.Stride:SignedInteger

    Conformances

    Members

    Citizens in Swift

    where Bound:Comparable

    Conformances

    Members

    Features

    Citizens in Swift

    where Bound:Comparable, Bound:Decodable

    Conformances

    Members

    Citizens in Swift

    where Bound:Comparable, Bound:Encodable

    Conformances

    Members

    Citizens in Swift

    where Bound:Comparable, Bound:Sendable

    Conformances

    • protocol Sendable

      A type whose values can safely be passed across concurrency domains by copying.

    Citizens in Swift

    where Bound:Comparable, Bound:Hashable

    Conformances

    • protocol Hashable

      A type that can be hashed into a Hasher to produce an integer hash value.

    Members

    Available in _RegexParser

    where Bound:Comparable

    Members

    Available in Foundation

    where Bound:BinaryInteger

    Members

    Available in Foundation

    where Bound == AttributedString.Index

    Members

    Available in Foundation

    where Bound == String.Index

    Members

    Available in Foundation

    where Bound == Int

    Members

    Extension in Markdown

    where Bound == SourceLocation

    Members