Reputation: 1490
I know that this has been asked before but I have gone through some of the previous questions and I cannot relate them to my problem.
I'm trying to develop a class in my application that will handle all of the calculations to be performed but I am having a problem with one of the more simple method calls trying to return a double value. I am pretty new to iOS coding so it is probably something simple that I am doing wrong. Anyway here is the code
P.S. I'm not sure if I have given enough information so if I need to add anything else let me know
from the .m file making the method call
- (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];
}
}
from the .m file where the method is located (the calculations class)
@implementation BIDCalculations
+ (double)calculateSpeed:(CLLocation *)newLocation;
{
return newLocation.speed;
}
from the .h file for the calculations class
@interface BIDCalculations : NSObject
+ (double)calculateSpeed:(CLLocation *)newLocation;
@end
Upvotes: 1
Views: 4531
Reputation:
+ (double)calculateSpeed:(CLLocation *)newLocation
That method already returns a double
.
double currentSpeed = [BIDCalculations calculateSpeed:newLocation];
is enough.
Upvotes: 0
Reputation: 122401
Your method is already returning a double
so change the problem line to:
double currentSpeed = [BIDCalculations calculateSpeed:newLocation];
Upvotes: 4