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

allSatisfy(_:)

Returns a Boolean value indicating whether every element of a sequence satisfies a given predicate. シーケンスのすべての要素がある与えられた述部を満たすかどうかを指し示すブール値を返します。

Declaration 宣言

func allSatisfy(_ predicate: (Element) throws -> Bool) rethrows -> Bool

Parameters パラメータ

predicate

A closure that takes an element of the sequence as its argument and returns a Boolean value that indicates whether the passed element satisfies a condition. あるクロージャ、それはこのシーケンスの1つの要素をそれの引数として取り、渡された要素がある条件を満たすかどうかを指し示すブール値を返します。

Return Value 戻り値

true if the sequence contains only elements that satisfy predicate; otherwise, false. true、もしシーケンスがpredicateを満たす要素のみを含むならば;そうでなければ、false

Discussion 解説

The following code uses this method to test whether all the names in an array have at least five characters: 以下のコードは、このメソッドを使って、配列の中の全ての名前が少なくとも5つの文字を含むかどうかを試験します:


let names = ["Sofia", "Camilla", "Martina", "Mateo", "Nicolás"]
let allHaveAtLeastFive = names.allSatisfy({ $0.count >= 5 })
// allHaveAtLeastFive == true

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

See Also 参照

Finding Elements 要素を見つける