⚠️ rely(the place:) was faraway from Swift 5 in Xcode 10.2 beta 4.
With Swift 5 and Xcode 10.2 beta 3, you need to 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: (Component) throws -> Bool) rethrows -> Int
Returns the variety of parts within the sequence that fulfill the given predicate.
The next Playground pattern code exhibits easy methods to use rely(the place:):
struct Particular person {
let identify: 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: Particular person) -> Bool in
return individual.isManager
})
// let managerCount = array.rely { $0.isManager } // additionally works
print(managerCount) // prints: 3