经过一番搜索,我找到了以下解决方案:参考链接。
CLLocationCoordinate2D* new_coordinate = malloc(sizeof(CLLocationCoordinate2D));
new_coordinate->latitude = latitude;
new_coordinate->longitude = longitude;
[points addObject:[NSData dataWithBytes:(void *)new_coordinate
length:sizeof(CLLocationCoordinate2D)]];
free(new_coordinate);
并且可以这样访问它:
CLLocationCoordinate2D* c = (CLLocationCoordinate2D*) [[points objectAtIndex:0] bytes];
但是,有人声称这里存在内存泄漏?有人能建议我泄漏在哪里以及如何修复它吗?此外,有没有更好的方法将CLLocationCoordinate2D列表存储在NSMutableArray中?由于我是Objective C新手,请提供示例代码。