[ad_1]
⚠️ rely(the place:)
was faraway from Swift 5 in Xcode 10.2 beta 4.
With Swift 5 and Xcode 10.2 beta 3, you should use Array
‘s rely(the place:)
methodology if you wish to rely the variety of parts in an array that match a given predicate. rely(the place:)
has the next declaration:
func rely(the place predicate: (Aspect) throws -> Bool) rethrows -> Int
Returns the variety of parts within the sequence that fulfill the given predicate.
The next Playground pattern code exhibits find out how to use rely(the place:)
:
struct Individual {
let title: String
let isManager: Bool
}
let array = [
Person(name: "Jane", isManager: true),
Person(name: "Bob", isManager: false),
Person(name: "Joe", isManager: true),
Person(name: "Jill", isManager: true),
Person(name: "Ted", isManager: false)
]
let managerCount = array.rely(the place: { (individual: Individual) -> Bool in
return individual.isManager
})
// let managerCount = array.rely { $0.isManager } // additionally works
print(managerCount) // prints: 3
[ad_2]
Source link