Question

I made an NSMUtableArray of CGpoints and I stored them by subclassing as NSValue, but I cant get the values out. here I what I did.

 CGPoint graphPoint;
    NSMutableArray *pointValues = [[NSMutableArray alloc] init];

    for( int x =0;x<5; x++)
    {
    NSDictionary* xValue = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:x] forKey:@"X"];
    graphPoint.x =x;
    graphPoint.y = [CalculatorBrain runProgram: self.graphingPoint usingVariableValues:xValue];

    [pointValues addObject:[NSValue valueWithCGPoint:graphPoint]];

}

I tried using this to get the values but I just get null back

for( int x=0; x<5; x++) {
NSValue *val = [pointValues objectAtIndex:x];
CGPoint point = [val CGpointValue];
NSLog(@"Points = %@", point);
}
Was it helpful?

Solution

You can't print a CGPoint using the %@ format specifier, as it is not an object. Instead, use NSStringFromCGPoint():

NSLog(@"%@", NSStringFromCGPoint(myPoint));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top