func stride<T>(from: T, through: T, by: T.Stride) -> StrideThrough<T>
The starting value to use for the sequence. If the sequence contains any values, the first one is start
.
シーケンスに使うための開始値。シーケンスが何らかの値を含むならば、最初のものはstart
です。
Availability
Technology
func stride<T>(from start: T, to end: T, by stride: T.Stride
) -> StrideTo
<T> where T : Strideable
start
The starting value to use for the sequence. If the sequence contains any values, the first one is start
.
シーケンスに使うための開始値。シーケンスが何らかの値を含むならば、最初のものはstart
です。
end
An end value to limit the sequence. end
is never an element of the resulting sequence.
シーケンスに限界を設けるための終了値。end
は、決して結果シーケンスの要素ではありません。
stride
The amount to step by with each iteration. A positive stride
iterates upward; a negative stride
iterates downward.
各反復でそれだけ間隔をとることになる量。正のstride
は上向きに反復していきます;負のstride
は下向きに反復していきます。
A sequence from start
toward, but not including, end
. Each value in the sequence steps by stride
.
start
から、そして含めずに、end
へ向かってのシーケンス。このシーケンスの各値は、stride
だけまたいで越えます。
You can use this function to stride over values of any type that conforms to the Strideable
protocol, such as integers or floating-point types. Starting with start
, each successive value of the sequence adds stride
until the next value would be equal to or beyond end
.
あなたは、この関数を使ってStrideable
プロトコルに準拠する任意の型、例えば整数や浮動小数点型の値いくつかをまたいで越すことができます。start
で開始して、シーケンスのそれぞれ次の値はstride
を、次の値がend
に等しいか越えるまで加えます。
for radians in stride(from: 0.0, to: .pi * 2, by: .pi / 2) {
let degrees = Int(radians * 180 / .pi)
print("Degrees: \(degrees), radians: \(radians)")
}
// Degrees: 0, radians: 0.0
// Degrees: 90, radians: 1.5707963267949
// Degrees: 180, radians: 3.14159265358979
// Degrees: 270, radians: 4.71238898038469
You can use stride(from:
to create a sequence that strides upward or downward. Pass a negative value as stride
to create a sequence from a higher start to a lower end:
あなたは、stride(from:
を使って上向きまたは下向きにまたいで越えるシーケンスを作成できます。負の値をstride
として渡して、上方から開始して下方に終わるシーケンスを作成してください:
for countdown in stride(from: 3, to: 0, by: -1) {
print("\(countdown)...")
}
// 3...
// 2...
// 1...
If you pass a value as stride
that moves away from end
, the sequence contains no values.
あなたがある値をstride
として渡してそれがend
から離れていくならば、シーケンスは全く値を含みません。
for x in stride(from: 0, to: 10, by: -1) {
print(x)
}
// Nothing is printed.
func stride<T>(from: T, through: T, by: T.Stride) -> StrideThrough<T>