我用Swift编写了一个应用程序,并正在连接一些Objective代码。其中一个类的方法如下所示:+ (CLLocationCoordinate2D *)polylineWithEncodedString:(NSString *)encodedString;。
在Swift中,它说这个方法返回一个UnsafeMutablePointer<CLLocationCoordinate2D>。我想要的是一个Swift数组的CLLocationCoordinate2D。
显然不起作用的是,但我试过了,这是:
let coordinates: [CLLocationCoordinate2D] = TheClass.polylineWithEncodedString(encodedString)这将给我以下错误:
'UnsafeMutablePointer<CLLocationCoordinate2D>' is not convertible to '[CLLocationCoordinate2D]'是否有可能将此UnsafeMutablePointer<CLLocationCoordinate2D>转换为[CLLocationCoordinate2D]?还是我该换个办法?
发布于 2015-01-08 13:17:55
您可以只使用UnsafeMutablePointer的内存属性,它是指针后面的数据。但是请记住,UnsafeMutablePointer < CLLocationCoordinate2D >将返回一个CLLocationCoordinate2D,而不是一个数组,就像obj函数中声明的那样。
var coordinate: CLLocationCoordinate2D = TheClass.polylineWithEncodedString(encodedString).memoryhttps://stackoverflow.com/questions/27839745
复制相似问题