// using function as parameters.
func isThereAMatch(listOfNumbers: [Int], condition: (Int) -> Bool) -> Bool {
for item in listOfNumbers {
if condition(item) {
return true
}
}
Unrelated to your original problem, but this implementation is incorrect. It'll treat all negative numbers as even. (E.g. -3 % 2 is -1, which is not > 0).
Back to the original question, if I understood correctly, the concern is about isThereAMatch having two return statements? If so, this return statements serve two different logical branches:
If during iteration over the list of numbers, condition has returned true for an item, the function returns true and ends its execution. It might not iterate over the whole list if matching item appears early.
If none of the list elements has matched the condition, first return statement would never fire and the function "fallback" to the second one.
Also, Swift has in latest versions, if I remember correctly, method on collections/sequences named contains(where:) accepting a predicate:
[2, 4, 6, 7].contains(where: { e in !e.isMultiple(of: 2) })