Storing and retrieving CGPoints inside NSMutableArray

Posted by Matt Dice on Stack Overflow See other posts from Stack Overflow or by Matt Dice
Published on 2010-03-21T06:54:10Z Indexed on 2010/03/21 7:01 UTC
Read the original article Hit count: 199

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.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c