Storing and retrieving CGPoints inside NSMutableArray
- by Matt Dice
I've looked through countless questions on here and elsewhere and cannot for the life of me figure out what I'm doing wrong.
I'm trying to store an array of CGPoints as NSValues inside of an NSMutableArray named points like so on the iPhone:
NSValue *point = [NSValue valueWithCGPoint:firstTouch];
NSLog(@"NSValue *point = %@", point);
[points addObject:point];
NSLOG OUTPUT
NSValue *point = NSPoint: {120, 221}
Everything is going smooth converting from the CGPoint to NSValue. But when I try to retrieve the point I get nothing.
NSValue *getPoint = [points objectAtIndex:0];
CGPoint thePoint = [getPoint CGPointValue];
NSLog(@"Point = %@", NSStringFromCGPoint(thePoint));
NSLOG OUTPUT
Point = {0, 0}
The points should be the same but I'm getting a null result.
For testing purposes this is happening in the touchesBegan method.
Does anyone have any idea where I'm going wrong? Thanks in advance.