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

contains(_:)

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

Declaration 宣言

func contains(_ element: UInt8) -> Bool

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はシーケンスの長さです。