Search code examples
objective-cxcodeswiftmkmapviewmkpolyline

MKMapPoint is not convertible to Void error


I am trying to draw a path on MKMapView from list of coordinates but I get two errors.
This is code (error lines have comments):

var routes = [CoordVO]();
        routes.append(pn)
        routes.appe...

        var a = UInt(sizeof(CLLocationCoordinate2D)) * UInt(routes.count)
        var pointArr = malloc(a)

        for var idx = 0; idx < routes.count; idx++ {

            var obj = routes[idx]

            var workingCoordinate:CLLocationCoordinate2D!
            workingCoordinate.latitude=obj.lat
            workingCoordinate.longitude=obj.lng

            var point = MKMapPointForCoordinate(workingCoordinate)
            pointArr[idx] = point; // MKMapPoint is not convertible to Void

        }

        var routeLine = MKPolyline(points: pointArr, count: routes.count) // Void is not identical to MKMapPoint

        self.mapView.addOverlay(routeLine)

        free(pointArr);

Solution

  • Look at the definition of the MKPolyline init method:

    init!(points points: UnsafeMutablePointer<MKMapPoint>, count count: Int)
    

    It needs an UnsafeMutablePointer<MKMapPoint>, but with malloc you create an UnsafeMutablePointer<Void>, that causes the problem.