⚠️ 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:) technique if you wish to rely the variety of components 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 components within the sequence that fulfill the given predicate.
The next Playground pattern code exhibits find out how to use rely(the place:):
struct Particular person {
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: { (particular person: Particular person) -> Bool in
return particular person.isManager
})
// let managerCount = array.rely { $0.isManager } // additionally works
print(managerCount) // prints: 3