Pregunta

I am trying to return the contents of my NSURL request as an integer/numerical value rather than an NSString. I have had quite a bit of trouble with this. Does anyone know what the last line of code needs to be to do this? Thank you!

NSString *distanceURL = [NSString stringWithFormat:@"http://www.website.com/distance.php?lat1=%@&lon1=%@&lat2=%@&lon2=%@",userLatitude, userLongitude, placeLatitude, placeLongitude];

NSData *distanceURLResult = [NSData dataWithContentsOfURL:[NSURL 
URLWithString:distanceURL]];

int distanceInFeet = distanceURLResult;
¿Fue útil?

Solución

Try:

int distanceInFeet = [[[NSString alloc] initWithData:distanceURLResult encoding:NSUTF8StringEncoding] integerValue];

Check for the correct encoding of the returned data.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top