Instance Method インスタンスメソッド

overlaps(_:)

Returns a Boolean value indicating whether this range and the given range contain an element in common. この範囲と与えられた範囲がある要素を共通に含むかどうかを指し示すブール値を返します。

Declaration 宣言

func overlaps(_ other: Range<Bound>) -> Bool

Parameters パラメータ

other

A range to check for elements in common. 共通の要素を調べる範囲。

Return Value 戻り値

true if this range and other have at least one element in common; otherwise, false. この範囲とotherが少なくとも1つの共通の要素を持つならば、true;そうでなければ、false

Discussion 解説

This example shows two overlapping ranges: この例は2つの重なった範囲を示します:


let x: Range = 0..<20
print(x.overlaps(10...1000))
// Prints "true"

Because a half-open range does not include its upper bound, the ranges in the following example do not overlap: 半壊範囲はそれの上方の範囲を含まないことから、以下の例の範囲は重なりません:


let y = 20..<30
print(x.overlaps(y))
// Prints "false"

See Also 参照

Comparing Ranges 範囲の比較