我该如何与以前使用大小为C数组的swift函数进行交互?
我阅读了与C API交互,但仍无法弄清楚。
我尝试了几种方法,最近的一种是:
抓狂了...有什么想法吗?
我阅读了与C API交互,但仍无法弄清楚。
func getCoordinates(_ coords:UnsafeMutablePointer<CLLocationCoordinate2D>,range range:NSRange)
的coords参数文档说明:“在输入时,您必须提供足够大以容纳所需坐标数的结构体的C数组。在输出上,此结构包含请求的坐标数据。”我尝试了几种方法,最近的一种是:
var coordinates: UnsafeMutablePointer<CLLocationCoordinate2D> = nil
polyline.getCoordinates(&coordinates, range: NSMakeRange(0, polyline.pointCount))
我需要使用类似这样的东西吗:
var coordinates = UnsafeMutablePointer<CLLocationCoordinate2D>(calloc(1, UInt(polyline.pointCount)))
抓狂了...有什么想法吗?
var coordinates = UnsafeMutablePointer<CLLocationCoordinate2D>()
? - Mike S'UnsafeMutablePointer<CLLocationCoordinate2D>'与'CLLocationCoordinate2D'不相同
,这对我来说真的没有任何意义,因为在函数中应该也是UnsafeMutablePointer<CLLocationCoordinate2D>'
。 - Andrew Robinsonvar coordinates = [CLLocationCoordinate2D]()
没有编译错误,但是getCoordinates
函数没有将任何内容返回给&coordinates
。 - Andrew Robinson