What do we need to do:
Iterate the array, for each station found, iterate over its sensor array. For each sensor found, keep only its id.
let ids = stations.map{ aStation in aStation.sensors.map{ $0.id } }.flatMap{ $0 }
With Sample:
struct StationItem {
let id: Int
let sensors: [SensorItem]
}
struct SensorItem {
let id: Int
}
let stations: [StationItem] = [StationItem(id: 114, sensors: [SensorItem(id: 642),
SensorItem(id: 644)]),
StationItem(id: 70, sensors: [SensorItem(id: 397),
SensorItem(id: 400),
SensorItem(id: 2014)])]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…