坏接收器类型'双'

时间:2013-03-01 14:26:07

标签: objective-c

我知道之前已经问过这个问题,但我已经完成了之前的一些问题,而且我无法将它们与我的问题联系起来。

我正在尝试在我的应用程序中开发一个类来处理要执行的所有计算,但是我遇到了一个更简单的方法调用试图返回double值的问题。我对iOS编码很陌生,所以我做错了可能很简单。无论如何这里是代码

P.S。我不确定我是否提供了足够的信息,所以如果我需要添加任何其他信息,请告诉我

从.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

2 个答案:

答案 0 :(得分:3)

您的方法已经返回double,因此请将问题行更改为:

double currentSpeed = [BIDCalculations calculateSpeed:newLocation];

答案 1 :(得分:0)

+ (double)calculateSpeed:(CLLocation *)newLocation

该方法已经返回double

double currentSpeed = [BIDCalculations calculateSpeed:newLocation];

就够了。