Swift provides map
, filter
, reduce
, ... for Array
\'s, but I am not finding some
(or any
) or
Update:
Use allSatisfy (all
) and contains(where:) (some
).
Old answer:
Just use contains.
// check if ALL items are completed
// so it does not contain a single item which is not completed
!items.contains { !$0.completed }
// check if SOME item is completed
// so test if there is at least one item which is completed
items.contains { $0.completed }