
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’)的参数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)