In my driver class I call this method:
NSMutableArray *test = [[myGrid getLoc:5 : 5] getAdjacentLocation: 2 : 2];
The header and the first line of the implementation of getAdjacentLocation is:
- (NSMutableArray*) getAdjacentLocation: (int)w: (int)h{
NSLog(@"checkpoint");
}
The implementation of getLoc is:
- (Location*)getLoc:(int)i : (int)j {
NSLog(@"check");
return (Location*)locations[i][j];
}
This is suppose to return a location out of an 2d array. Although the NSLog is call, I dont think it returns it properly?
(can I get 2d arrays with properties?)
I init locations like this
int x = 0;
int y = 0;
//row
for(int i = 0; i < 1000; i+=40){
//column
for(int j = 0; j < 1000; j+=40) {
locations[y][x] = [[Location alloc] initWithPosition:CGPointMake(i, j)];
NSLog(@"%@" ,NSStringFromCGPoint(locations[y][x].locPosition));
y++;
}
x=0;
y++;
}
I could be doing something stupid with memory management as this is completely new to me.
The first statement in this method of getadjacentlocation is not executed. Why?
This is probably a very stupid mistake, but can anyone help me out here?
Thanks.
Your
getLoc::method is probably returningnil, because in your locations initialization code, you’re only incrementingy, notx, leaving most of the elements of location undefined. Fix your loop to increment x inside the column for loop.