0

I need to convert NSValues from a dictionary to CGPoint.

Example: I have a dictionary with 2 items in it:

NSValue *p1 = [dict objectForKey:@"LATITUDE"];
NSValue *p2 = [dict objectForKey:@"LONGITUDE"];

When I try this, it gives an error

CGPoint point = CGPointMake((CGFloat)p1;, (CGFloat)p2);
sia
  • 1,872
  • 1
  • 23
  • 54
  • 4
    `CGPoint point = CGPointMake([p1 floatValue], [p2 floatValue])`? But why `NSValue`? Are you sure they are `NSValue` objects, `NSNumber` usually is enough? Why not using already https://stackoverflow.com/questions/772958/converting-a-cgpoint-to-nsvalue to store points? – Larme Oct 11 '17 at 12:15
  • @Larme - tried CGPoint point = CGPointMake([p1 floatValue], [p2 floatValue]).. did not work – sia Oct 11 '17 at 12:46
  • `NSLog(@"Latitude Class :%@", [[dict objectForKey:@"LATITUDE"] class])` that prints what exactly? I checked, NSValue doesn't have `floatValue`, `NSNumber` does. It shouldn't be a `NSValue`. – Larme Oct 11 '17 at 12:49
  • There‘s an extra semicolon in your statement‘s parameter list. But beyond that, you can‘t just cast an object address to get a float. You need to call a method on that object that will get that float from the object, like floatValue. – uliwitness Oct 11 '17 at 16:21

0 Answers0