I have the following Object Array for the Place class:
class Place: NSObject {
var distance:Double = Double()
init(_ distance: Double) {
self.distance = distance
}
}
let places = [Place(1.5), Place(8.4), Place(4.5)]
I need to get the Place with the minimum distance. I tried using
let leastDistancePlace = places.min { $0.distance > $1.distance }
as per this answer for a similar question, but it gave the following error.
Contextual closure type '(Place) -> _' expects 1 argument, but 2 were used in closure body
PS:
As per @robmayoff 's answer, I tried the following in a playground, but I keep getting an error:
value of Type [Place] no member min
My swift version is : Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31)