CLLocationCoordinate2D

CLLocationCoordinate2D

我有一个方法应该返回非对象类型的列表。特别是CLLocationCoordinate2D的列表。我想将其作为列表而不是NSArray我使用结果使用创建一个MKPolyLine

+ (MKPolyline *)polylineWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count


通过下面的代码,我得到了“数组初始化器必须是初始化器”列表。

 -(CLLocationCoordinate2D[])pathBetween:(CLLocationCoordinate2D)start and:(CLLocationCoordinate2D)end withNumberofPoints:(int)nrOfPoints{
CLLocationCoordinate2D returnPath[nrOfPoints];
for (int i=0; 1<nrOfPoints; i++) {
    float fraction=i/(nrOfPoints);
    CLLocationCoordinate2D coord=[self coordinateAtFraction:fraction between:start andEnd:end forAccuracy:.02];
    returnPath[i]=coord;
}
return returnPath;


}

如果我使用初始化列表

CLLocationCoordinate2D returnPath[nrOfPoints]={};


我得到“可变大小的对象可能未初始化”。
如果从方法中删除[],则会得到“从结果类型不兼容的函数“ CLLocationCoordinate2D [nrOfPoints]返回CLLocationCoordinate2D”返回“”

有任何想法吗?

最佳答案

CLLocationCoordinate2D returnPath[nrOfPoints];在编译时,没有Point的值应该可用。如果您用CLLocationCoordinate2D *returnPath = (CLLocationCoordinate2D *) malloc(nrOfPoints * sizeof (CLLocationCoordinate2D));替换行
数组将在运行时可用。但是我不确定sizeof方法是否会返回对象的大小。

关于iphone - 如何在Objective-C中返回非对象类型的数组列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8047297/

10-13 09:01