Operator 演算子

...(_:)

Returns a partial range up to, and including, its upper bound. それの上側の境界までの、そしてそれを含む部分的な範囲を返します。

Declaration 宣言

prefix static func ... (maximum: String) -> PartialRangeThrough<String>

Parameters パラメータ

maximum

The upper bound for the range. 範囲の上側の境界。

Discussion 解説

Use the prefix closed range operator (prefix ...) to create a partial range of any type that conforms to the Comparable protocol. This example creates a PartialRangeThrough<Double> instance that includes any value less than or equal to 5.0. 前置完結範囲演算子(前置...)を使うことで何らかの型の部分的な範囲でComparableプロトコルに準拠するものを作成してください。この例は、PartialRangeThrough<Double>インスタンスで5.0より少ないか等しい何らかの値を含むものを作成します。


let throughFive = ...5.0


throughFive.contains(4.0)     // true
throughFive.contains(5.0)     // true
throughFive.contains(6.0)     // false

You can use this type of partial range of a collection’s indices to represent the range from the start of the collection up to, and including, the partial range’s upper bound. あなたは、あるコレクションのインデックスからなる、この型の部分的範囲を使うことで、コレクションの始まりからその部分的な範囲の上側の境界までの、そしてそれを含んでいる範囲を表すことができます。


let numbers = [10, 20, 30, 40, 50, 60, 70]
print(numbers[...3])
// Prints "[10, 20, 30, 40]"

Precondition: maximum must compare equal to itself (i.e. cannot be NaN). 前提条件:maximumはそれ自身と等しいと比較されなければなりません(すなわちNaNであることはできません)。

See Also 参照

Creating a Range Expression 範囲式を作成する