struct
Range
<
T
:
ForwardIndexType
>
Inheritance |
CollectionType, DebugPrintable, Equatable, Printable, Reflectable, SequenceType, _CollectionType, _SequenceType, _Sequence_Type
View Protocol Hierarchy →
|
---|---|
Associated Types |
A type that represents a valid position in the collection. Valid indices consist of the position of every element and a "past the end" position that's not valid for use as a subscript.
A type whose instances can produce the elements of this sequence, in order.
Type alias inferred.
Type alias inferred.
Type alias inferred. |
Import |
|
Initializers
Construct a range with startIndex == start
and endIndex ==
end
.
Declaration
init
(
start
:
T
,
end
:
T
)
Instance Variables
A textual representation of self
, suitable for debugging.
Declaration
var
debugDescription
:
String
{
get
}
The range's upper bound
endIndex
is not a valid argument to subscript
, and is always
reachable from startIndex
by zero or more applications of
successor()
.
Declaration
var
endIndex
:
T
{
get
set
}
The range's lower bound
Identical to endIndex
in an empty range.
Declaration
var
startIndex
:
T
{
get
set
}
Subscripts
Declaration
subscript
(
position
:
T
) -
>
T
{
get
}
Declaration
subscript
(
_
:
T
.
_DisabledRangeIndex
) -
>
T
{
get
}
Instance Methods
Return a generator over the elements of this sequence.
Complexity: O(1)
Declaration
func
generate
() -
>
RangeGenerator
<
T
>
Return an array containing the results of calling
transform(x)
on each element x
of self
.
Declaration
func
map
<
U
>
(
transform
: (
T
) -
>
U
) -
>
[
U
]
A collection of consecutive discrete index values.
T
is both the element type and the index type of the collection.Like other collections, a range containing one element has an
endIndex
that is the successor of itsstartIndex
; and an empty range hasstartIndex == endIndex
.Axiom: for any
Range
r
,r[i] == i
.Therefore, if
T
has a maximal value, it can serve as anendIndex
, but can never be contained in aRange<T>
.It also follows from the axiom above that
(-99..<100)[0] == 0
. To prevent confusion (because some expect the result to be-99
), in a context whereT
is known to be an integer type, subscripting withT
is a compile-time error:However, subscripting that range still works in a generic context: