james james - 10 months ago 72
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 ||.