ios - 具有多重验证的对象数组过滤器

标签 ios arrays swift

我有一个 User 对象数组,其中的状态为属性。

现在我想使用状态来过滤对象,它可以

状态: 等待 进行中 正研 没兴趣 不适用 有兴趣 已预订

多一项属性(property)资格 10 20 30

let array = Array<User> // assuming this has array of user values

let filteredArray = array.filter { !$0.status.contains("Waiting") || !$0.status.contains("JustResearch") !$0.status.contains("AlreadyBooked") || !$0.eligibility.contains("20")}

我需要像上面这样的filteredArray应该只包含具有InProgress、JustResearch、NotInterested和NotApplicable的用户对象

当我尝试使用上面的过滤器时出现错误,如何应用具有多个条件的过滤器。

最佳答案

您在

之后丢失了||
!$0.status.contains("JustResearch")

这段代码可以工作:

let filteredArray = array.filter { !$0.status.contains("Waiting") || !$0.status.contains("JustResearch") || !$0.status.contains("AlreadyBooked")}

关于ios - 具有多重验证的对象数组过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45954152/

相关文章:

swift - 如何通过可选的字典修改值类型的值?

ios - Textfield 确实结束了编辑崩溃应用程序

ios - 条形项按钮在运行时不显示,但在设计时在模态视图中可见

ios - 在 xcode 的两个不同类中重用相同的方法(功能)

ios - 从键值对数组创建键数组

c - 数组中的字符串到另一个数组中

php - 在 PHP 中将数组元素添加到子数组

swift - 添加了隐私 key ,但在关闭 UIImagePickerController 时仍然崩溃

iphone - 我可以淡化/动画 UIToolbar 的 tintColor 吗?

ios - Swift:UICollectionViewCell didSelectItemAtIndexPath 改变背景颜色