james james - 1 year ago 132
Swift Question

Check if swift array does not contain object

I'm trying to filter a list of users from a Firebase query so that I only get users that are NOT listed in one of two arrays. The code I'm using doesn't work:

let users = snapshot.childSnapshots.map {
User(snapshot: $0)
guardiansArray.contains($0.key) == false || dependentsArray.contains($0.key) == false

If I remove the
code, I get the opposite effect of what I want: I get a list of users that ARE in either of the two arrays. How can I get the reverse effect?


Answer Source

It looks like you want to use && instead of ||.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download