james james - 10 days ago 6
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)
}.filter{
guardiansArray.contains($0.key) == false || dependentsArray.contains($0.key) == false
}


If I remove the
==false
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?

Thanks!

Answer

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

Comments