Initializer

init(_:)

Creates an instance equivalent to the given ClosedRange.

Declaration

init(_ other: ClosedRange<Bound>)
Available when Bound conforms to Strideable and Bound.Stride conforms to SignedInteger.

Parameters

other

A closed range to convert to a Range instance.

Discussion

An equivalent range must be representable as an instance of Range<Bound>. For example, passing a closed range with an upper bound of Int.max triggers a runtime error, because the resulting half-open range would require an upper bound of Int.max + 1, which is not representable as

See Also

Converting Ranges

func relative<C>(to: C) -> Range<Bound>

Returns the range of indices described by this range expression within the given collection.

init?(NSRange, in: String)