检查swift数组是否不包含对象(Check if swift array does not contain object)
我正在尝试从Firebase查询中过滤用户列表,以便我只获得未列在两个阵列之一中的用户。 我正在使用的代码不起作用:
let users = snapshot.childSnapshots.map { User(snapshot: $0) }.filter{ guardiansArray.contains($0.key) == false || dependentsArray.contains($0.key) == false }如果我删除==false代码,我会得到与我想要的相反的效果:我得到两个数组中任何一个的用户列表。 如何获得相反的效果?
谢谢!
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!
最满意答案
看起来你想使用&&而不是|| 。
It looks like you want to use && instead of ||.
更多推荐
发布评论