检查swift数组是否不包含对象(Check if swift array does not contain object)

编程入门 行业动态 更新时间:2024-10-25 18:23:28
检查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 ||.

更多推荐

本文发布于:2023-08-07 16:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465127.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   不包含   对象   swift   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!