我有两个 NSArray,一个是 CLLocation,一个是 double (包含在对象中),我需要将它们写入 C vector 以绘制此处定义的渐变 MKPolyline ( https://github.com/wdanxna/GradientPolyline )。我尝试复制我在那里看到的一些代码,准备调用其函数之一:
points = malloc(sizeof(CLLocationCoordinate2D)*self.run.locations.array.count);
velocity = malloc(sizeof(float)*self.run.locations.array.count);
for(int i = 0; i<self.run.locations.array.count; i++){
points[i] = self.run.locations.array[i];
velocity[i] = [velocities[i] floatValue];
}
这里 self.run.locations.array 是一个 CLLocations
数组。
现在我什至无法构建项目,因为我还没有声明变量。但是我在哪里/如何声明这些变量呢?我不懂 C,而且我尝试使用的项目似乎没有将这些声明包含在我可以找到的地方。
最佳答案
points
是一个 CLLocationCooperative2D
数组(动态分配),因此它应该是一个指向 CLLocationCooperative2D
的指针,即
CLLocationCoordinate2D *points;
velocity
是一个 float
数组,因此应声明为
float *velocity;
或者你也可以这样做
float velocity[];
如果您更喜欢数组语法。
关于objective-c - 如何在 Objective-C 应用程序中声明 C 风格数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30218632/