I’m developing an iPhone application and I getting that warning at method:
NSNumber *latitudeValue;
NSNumber *longitudeValue;
[self obtainLatitude:latitudeValue longitude:longitudeValue];
The method is declared as follows:
- (void) obtainLatitude:(NSNumber *)latitudeValue longitude:(NSNumber *)longitudeValue {
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
latitudeValue = [f numberFromString:[latitude.text stringByReplacingOccurrencesOfString:@"," withString:@"."]];
longitudeValue = [f numberFromString:[longitude.text stringByReplacingOccurrencesOfString:@"," withString:@"."]];
[f release];
}
As you can see, I’m trying to calculate latitudeValue and longitudeValue calling obtainLatitude:longitude: but I’m doing something wrong.
How can I fix that error?
Elfred’s answer works, but pass-by-reference for non-NSError** parameters is pretty uncommon. As well, coordinates — numeric values, in general — are most typically stored in regular old C types in structures because, comparatively, an NSNumber is quite a bit of overhead (no big deal for a few of ’em, would be a problem if you have a few dozen, hundred, or thousands of coordinates).
Something like:
Then:
Something like the above would be more typical in an iPhone/Cocoa program.
As Dave points out, you really don’t need to define your own type for this. Use CLLocationCoordinate2D or CLLocation.