我知道以前有人问过这个问题,但我已经解决了之前的一些问题,但我无法将它们与我的问题联系起来。
我正在尝试在我的应用程序中开发一个类,该类将处理要执行的所有计算,但是我遇到了一个尝试返回双精度值的更简单方法调用的问题。我对 iOS 编码很陌生,所以我做错了可能很简单。无论如何这里是代码
PS我不确定我是否提供了足够的信息,所以如果我需要添加任何其他内容,请告诉我
从 .m 文件进行方法调用
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// print the location to the device logs to aid in debugging
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
//this is the problem line here
//Problem solved thans to trojanfoe and H2CO3
double currentSpeed = [[BIDCalculations calculateSpeed: newLocation] doubleValue];
//the problem line was replace with this new line which solved the error
double currentSpeed = [BIDCalculations calculateSpeed: newLocation];
// if there is a location to report, print it to the screen
if (currentLocation != nil) {
_positionLabel.text = [NSString stringWithFormat:@"%.3f, %.3f",
currentLocation.coordinate.longitude,
currentLocation.coordinate.latitude];
}
}
来自方法所在的 .m 文件(计算类)
@implementation BIDCalculations
+ (double)calculateSpeed:(CLLocation *)newLocation;
{
return newLocation.speed;
}
来自计算类的 .h 文件
@interface BIDCalculations : NSObject
+ (double)calculateSpeed:(CLLocation *)newLocation;
@end