Checking sequence elements match a condition
About 2 min
Checking sequence elements match a condition 관련
HACKING WITH SWIFT
What's new in Swift?
Checking sequence elements match a condition | Changes in Swift 4.2
Checking sequence elements match a condition
Available from Swift 4.2
SE-0207 (apple/swift-evolution
) provides a new allSatisfy()
method that checks whether all items in a sequence pass a condition.
For example, if we had an array of exam results like this:
let scores = [85, 88, 95, 92]
We could decide whether a student passed their course by checking whether all their exam results were 85 or higher:
let passed = scores.allSatisfy { $0 >= 85 }
Other Changes in Swift 4.2
Derived collections of enum cases | Changes in Swift 4.2
Derived collections of enum cases
Warning and error diagnostic directives | Changes in Swift 4.2
Warning and error diagnostic directives
Dynamic member look up | Changes in Swift 4.2
Dynamic member look up
Enhanced conditional conformances | Changes in Swift 4.2
Enhanced conditional conformances
Random number generation and shuffling | Changes in Swift 4.2
Random number generation and shuffling
Simpler, more secure hashing | Changes in Swift 4.2
Simpler, more secure hashing
In-place collection element removal | Changes in Swift 4.2
In-place collection element removal
Boolean toggling | Changes in Swift 4.2
Boolean toggling