0

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?

jscs
  • 63,694
  • 13
  • 151
  • 195
the pickle
  • 668
  • 8
  • 18
  • 1
    There are docs. If you lookup `valueWithCGPoint` the description provides the inverse operation with "See Also `– CGPointValue:`". – zaph Jul 30 '14 at 21:34
  • Can I still get credit for a chosen answer? – Wyetro Jul 30 '14 at 22:24

1 Answers1

2

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.

Community
  • 1
  • 1
Wyetro
  • 8,439
  • 9
  • 46
  • 64
  • I have one more question, is it computationally better to use CGPoint[] over NSMutableArray, and if it is how much better is it. – the pickle Aug 01 '14 at 01:30
  • Not sure, google it or ask a new question. – Wyetro Aug 01 '14 at 04:38
  • This doesn't work in XCode 10. – Jubei Aug 13 '19 at 22:02
  • @Jubei this is from over 5 years ago – Wyetro Aug 14 '19 at 04:28
  • @Wyetro I’m just adding knowledge to this post. Is this a reason for you to downvote me? I have improved the post in case somebody stumbles upon this today (like I did). – Jubei Aug 24 '19 at 11:48
  • @Jubei you can't downvote comments... My point was only that this is from a long time ago. Additionally, the link I have there has the solution: `CGPoint location = locationValue.CGPointValue` – Wyetro Aug 24 '19 at 19:37