【发布时间】:2019-05-30 20:41:57
【问题描述】:
考虑一个对象Notification,它具有以下属性:
id: String
body: String
repeats: Bool
考虑Notifications、notifications的数组:
let notifications = [Notification(id: "1", body: "body1", repeats: false),
Notification(id: "2", body: "body2", repeats: false),
Notification(id: "3", body: "body3", repeats: true)]
如何使用高阶filter() 函数来检索与每个id 对应的字符串 数组?
换句话说,我想写一个filter()闭包,我将notifications传递给它,结果输出是:
["1", "2", "3"]
因此,我的过滤器比较运算符应该基于属性名称。这可以实现吗?
【问题讨论】:
标签: swift filter higher-order-functions