I have mapView
of type MKMapView
and some annotations in the map. I am trying to calculate the median of the latitude of this annotations using reduce, but I get an error claiming:
Type of expression is ambiguous without more context.
Here is my code:
let medianLatitude = mapView.annotations.reduce( 0.0, { $0.coordinate.latitude + $1.coordinate.latitude })
When using
reduce
, the first parameter passed to the closure represents the partially accumulated result.In your case, its type needs to match the initial value
0.0
-- it'sDouble
.So, try this: