func showMarkers(markers: [Marker], value: Float) { // Remove all current overlays…
- User
func showMarkers(markers: [Marker], value: Float) { // Remove all current overlays map.removeOverlays(map.overlays) var lineCoords = CLLocationCoordinate2D for (index, marker) in markers.enumerated() { if(index > (value * markers.count)) { break } let hi = Double.random(in: (-90)..<90) let hi2 = Double.random(in: (-180)..<180) lineCoords.append(CLLocationCoordinate2D(latitude: hi, longitude: hi2)) } let line = MKPolyline(coordinates: lineCoords, count: lineCoords.count) map.addOverlay(line); }
Cannot convert value of type 'Float' to expected argument type 'Int'
- Assistant
The error message "Cannot convert value of type 'Float' to expected argument type 'Int'" in the Swift code snippet you posted is referring to the expression
(value * markers.count). Themarkers.countproperty is anIntbecause it represents the number of elements in an array, andvalueis aFloat. The multiplication of aFloatand anIntresults in aFloat, but the index of an array needs to be an .