Search code examples
objective-ccocoa-touchcocoacgpointnsvalue

Convert NSValue back to CGPoint


I made an NSMutableArray like this storing a bunch of CGPoints

    safeZonePoints = [NSMutableArray array];
    [safeZonePoints addObject:[NSValue valueWithCGPoint:CGPointMake(234, 160)]];
    [safeZonePoints addObject:[NSValue valueWithCGPoint:CGPointMake(284, 210)]];
    [safeZonePoints addObject:[NSValue valueWithCGPoint:CGPointMake(334, 160)]];
    [safeZonePoints addObject:[NSValue valueWithCGPoint:CGPointMake(284, 10)]];
    [safeZonePoints addObject:[NSValue valueWithCGPoint:CGPointMake(234, 160)]];

Now I can get the NSValues from the array, but how do I convert an NSValue back to CGPoint?


Solution

  • Do something like this:

    NSValue *cgpointObj = [NSValue valueWithCGPoint:CGPointMake(234, 160)];
    CGPoint loc = cgpointObj.pointValue;
    

    Check out the following link: CGPoint to NSValue and reverse

    It should be enough to answer your question.