【发布时间】:2018-11-09 06:26:48
【问题描述】:
假设我有如下数据。
[
{
hotelName : "Hotel 1",
hotelType : 1
prices :
[
{
roomType: "Single Room",
price : 1231
},
{
roomType: "Twin Room",
price : 1232
},
{
roomType: "Triple Room",
price : 1233
},
]
},
{
hotelName : "Hotel 2",
hotelType : 2
prices :
[
{
roomType: "Single Room",
price : 1241
},
{
roomType: "Twin Room",
price : 1242
},
{
roomType: "Triple Room",
price : 1243
},
]
}
]
我想要的是用价格过滤酒店。
假设我想过滤得到低于范围的酒店。
价格范围为 1231-1233 >> 这将只返回酒店 1。
价格范围为 1231-1431 >> 这将返回酒店 1 和酒店 2。
我有相同类型的过滤器,但我只有 1 个价格,所以我正在做的事情如下。
finalArray = finalArray.filter() {
CGFloat(($0.prices![0].price)!) >= minValue
&&
CGFloat(($0.prices![0].price)!) <= maxValue
}
但是现在我有一系列价格,所以我不知道在这种情况下如何处理。
问题出在一行
$0.prices![0].price
^^^
有人可以为我指出如何实现此过滤器的正确方向吗?
【问题讨论】:
-
您想从酒店数组中获取过滤后的项目吗?我的意思是 { roomType: String, price: Int }