我在与一个代码片段麻烦。 我试图CLLocationCoordinate2D的一个实例添加到使用AddObject方法NSMutable数组,但每当执行行,我的应用程序崩溃。 有什么明显的错误与此代码?
飞机坠毁在这一行:
[points addObject:(id)new_coordinate];
Polygon.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