Alexey K Alexey K - 1 year ago 72
Swift Question

Swift - check if array contains element with property

I have an array of custom objects.

I want to check if array contains an object, which property is equal to string.

Somethin like

if array.contains(object where == name) {
// do something
} else {
// dont do something

Is it possible to do in swift ?

Answer Source


if things.contains{ $0.someProperty == "nameToMatch" } {
    // found
else {
    //  not
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download