2012-11-17 20 views
5
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]; 

otrzymuję następujący błąd na linii # 3 powyżej:Wysyłanie 'NSNumber * __ silny' do parametru niekompatybilnych typu 'CLLocationDegrees' (aka 'double')

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

wiem, że to dlatego, Próbuję przekazać numer NSNumber do miejsca, w którym spodziewa się podwójne. Ale casting nie działa z powodu ARC?

+0

pamiętać, że nie są faktycznie odlewania cokolwiek w tym kodzie. (To nie pomogłoby, gdybyś to zrobił, ale pod względem identyfikacji obecnego problemu, to nie to.) –

+0

nie wiesz, kto jest w trakcie głosowania, ale widać, że ktoś się nudzi. Próbowałem upomnieć wszystkich, którzy odpowiedzieli – milof

Odpowiedz

3

Wezwanie do [cityDictionary valueForKeyPath:@"coordinates.latitude"] już daje obiekt NSNumber. Po co konwertować to na podwójne, a następnie utworzyć nowe NSNumber?

Można po prostu zrobić:

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

Jeśli okaże się, że rzeczywiście jest [cityDictionary valueForKeyPath:@"coordinates.latitude"] zwrócenie NSString a nie NSNumber, to zrobić:

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

Wysyłasz typ NSNumber do parametru double. Możesz rozważyć zmianę na CLLocationDegree lub double, ale jeśli używasz go gdzie indziej lub przechowujesz go z podstawowymi danymi, zostawiłbym go jako NSNumber.

CLLocation *listingLocation = [[CLLocation alloc] initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue]]; 
Powiązane problemy