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

contains(_:)

Returns a Boolean value indicating whether the sequence contains the given element. 指定された要素をシーケンスが含むかどうかを指し示すブール値を返します。

Declaration 宣言

func contains(_ element: Element) -> Bool
Available when Element conforms to Equatable. ElementEquatableに準拠する時に利用可能です。

Parameters パラメータ

element

The element to find in the sequence. このシーケンスにおいて見つける要素。

Return Value 戻り値

true if the element was found in the sequence; otherwise, false. 要素がシーケンスにおいて見つけられなかったならば、true;そうでなければ、false

Discussion 解説

This example checks to see whether a favorite actor is in an array storing a movie’s cast. この例は、映画出演者を格納する配列の中にお気に入りの俳優がいるかどうか確認するために調べます。


let cast = ["Vivien", "Marlon", "Kim", "Karl"]
print(cast.contains("Marlon"))
// Prints "true"
print(cast.contains("James"))
// Prints "false"

Complexity: O(n), where n is the length of the sequence. 計算量:O(n)、ここでnはシーケンスの長さです。

See Also 参照

Finding Elements 要素を見つける