-1
誰知道爲什麼會發生這種情況?排序斯威夫特代碼
它給我錯誤在Array(places).sorted { $0.1 < $1.1 }.map { $0.0 }
部分。
let placesByBeacons = [
"12103:16951": [
"Heavenly Sandwiches": 5, // read as: it's 5 meters from
// "Heavenly Sandwiches" to the beacon with
// major 6574 and minor 54631
"Green & Green Salads": 10,
"Mini Panini": 15
],
"648:12": [
"Heavenly Sandwiches": 250,
"Green & Green Salads": 100,
"Mini Panini": 20
],
"17581:4351": [
"Heavenly Sandwiches": 350,
"Green & Green Salads": 500,
"Mini Panini": 170
]
]
func placesNearBeacon(beacon: CLBeacon) -> [String]? {
let beaconKey = "\(beacon.major):\(beacon.minor)"
if let places = self.placesByBeacons[beaconKey] {
let sortedPlaces = Array(places).sorted { $0.1 < $1.1 }.map { $0.0 }
return sortedPlaces
}
return nil
}
'sorted' - >'sort' – Hamish