2012-11-17 12 views
5
Yukarıdaki çizgi 3. aşağıdaki hatayı alıyorum
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]; 

:Gönderme 'NSNumber * __ güçlü' uyumsuz tip 'CLLocationDegrees' parametresine (aka 'çift')

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

Biliyorum çünkü Bir NSNumber'i bir çift beklediği bir yere iletmeye çalışıyorum. Fakat ARC nedeniyle döküm çalışmıyor mu?

+0

Not Bu koddaki herhangi bir şey. (Yapmış olsaydın, şu anki problemi tanımlamak için işe yaramazdı, bu o değil.) –

+0

oylamadan kimin seçildiğinden emin değil ama birisi sıkılıyormuş gibi görünüyor. Cevap vermiş olan herkesi kışkırtmaya çalıştım – milof

cevap

3

[cityDictionary valueForKeyPath:@"coordinates.latitude"] çağrısı zaten size bir NSNumber nesneyi veriyor. Neden bunu ikiye dönüştürün ve yeni bir NSNumber oluşturun?

sadece yapabileceği:

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

o [cityDictionary valueForKeyPath:@"coordinates.latitude"] aslında bir NSString değil bir NSNumber dönüyor, sonra bunu ortaya çıkarsa: aslında döküm değildir

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

Çiftli bir parametreye NSNumber tipi gönderiyorsunuz. Bunu CLLocationDegree veya double olarak değiştirmeyi düşünebilirsiniz, ancak başka bir yerde kullanıyorsanız veya çekirdek verilerle depolarsanız onu NSNumber olarak bırakırdım.

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