我在处理一段代码时遇到了问题。我正在尝试使用 addObject 方法将 CLLocationCoordinate2D 的实例添加到 NSMutable 数组中,但是每当执行该行时,我的应用程序就会崩溃。这段代码有什么明显的问题吗?
崩溃发生在这一行:
[points addObject:(id)new_coordinate];
多边形.m:
#import "Polygon.h"
@implementation Polygon
@synthesize points;
- (id)init {
self = [super init];
if(self) {
points = [[NSMutableArray alloc] init];
}
return self;
}
-(void)addPointLatitude:(double)latitude Longitude:(double)longitude {
NSLog(@"Adding Coordinate: [%f, %f] %d", latitude, longitude, [points count]);
CLLocationCoordinate2D* new_coordinate = malloc(sizeof(CLLocationCoordinate2D));
new_coordinate->latitude = latitude;
new_coordinate->longitude = longitude;
[points addObject:(id)new_coordinate];
NSLog(@"%d", [points count]);
}
-(bool)pointInPolygon:(CLLocationCoordinate2D*) p {
return true;
}
-(CLLocationCoordinate2D*) getNEBounds {
...
}
-(CLLocationCoordinate2D*) getSWBounds {
...
}
-(void) dealloc {
for(int count = 0; count < [points count]; count++) {
free([points objectAtIndex:count]);
}
[points release];
[super dealloc];
}
@end