Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending 'NSNumber *__strong' to parameter of incompatible type 'CLLocationDegrees' (aka 'double')

Tags:

ios

cllocation

NSNumber * latitude =  [NSNumber numberWithDouble:[[cityDictionary valueForKeyPath:@"coordinates.latitude"]doubleValue]];

      NSNumber * longitude =  [NSNumber numberWithDouble:[[cityDictionary valueForKeyPath:@"coordinates.longitude"]doubleValue]];


    CLLocation *listingLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];

I am getting the following error on line # 3 above:

Sending 'NSNumber *__strong' to parameter of incompatible type 'CLLocationDegrees' (aka 'double')

I know it is because I am trying to pass a NSNumber to a place where it expects a double. But casting is not working due to ARC?

like image 456
milof Avatar asked Nov 17 '12 18:11

milof


2 Answers

The call to [cityDictionary valueForKeyPath:@"coordinates.latitude"] is already giving you an NSNumber object. Why convert that to a double and then create a new NSNumber?

You could just do:

NSNumber *latitude = [cityDictionary valueForKeyPath:@"coordinates.latitude"];
NSNumber *longitude = [cityDictionary valueForKeyPath:@"coordinates.longitude"];
CLLocation *listingLocation = [[CLLocation alloc] initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue]];

If it turns out that [cityDictionary valueForKeyPath:@"coordinates.latitude"] is actually returning an NSString and not an NSNumber, then do this:

CLLocationDegrees latitude = [[cityDictionary valueForKeyPath:@"coordinates.latitude"] doubleValue];
CLLocationDegrees longitude = [[cityDictionary valueForKeyPath:@"coordinates.longitude"] doubleValue];
CLLocation *listingLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
like image 77
rmaddy Avatar answered Sep 22 '22 06:09

rmaddy


You are sending type NSNumber to a parameter of double. You could consider changing it to CLLocationDegree's or double, but if you are using it elsewhere or storing it with core data I would leave it as NSNumber.

CLLocation *listingLocation = [[CLLocation alloc] initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue]];
like image 22
brightintro Avatar answered Sep 19 '22 06:09

brightintro