ios – 将’NSNumber * __ strong’发送到不兼容类型’CLLocationDegrees'(又名’double’)的参数

ios – 将’NSNumber * __ strong’发送到不兼容类型’CLLocationDegrees'(又名’double’)的参数,第1张

概述NSNumber * latitude = [NSNumber numberWithDouble:[[cityDictionary valueForKeyPath:@"coordinates.latitude"]doubleValue]]; NSNumber * longitude = [NSNumber numberWithDouble:[[cityDictionary val
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];

我在上面第3行收到以下错误:

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

我知道这是因为我试图将NSNumber传递到一个预期会有双倍的地方.但由于ARC,铸造不起作用?

解决方法 对[cityDictionary valueForKeyPath:@“coordinates.latitude”]的调用已经为您提供了一个NSNumber对象.为什么将它转换为double然后创建一个新的NSNumber?

你可以这样做:

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

如果事实证明[cityDictionary valueForKeyPath:@“coordinates.latitude”]实际上是返回Nsstring而不是NSNumber,那么执行以下 *** 作:

CLLocationdegrees latitude = [[cityDictionary valueForKeyPath:@"coordinates.latitude"] doubleValue];CLLocationdegrees longitude = [[cityDictionary valueForKeyPath:@"coordinates.longitude"] doubleValue];CLLocation *ListingLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
总结

以上是内存溢出为你收集整理的ios – 将’NSNumber * __ strong’发送到不兼容类型’CLLocationDegrees'(又名’double’)的参数全部内容,希望文章能够帮你解决ios – 将’NSNumber * __ strong’发送到不兼容类型’CLLocationDegrees'(又名’double’)的参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1068851.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存