Skip to content

Instantly share code, notes, and snippets.

@davidyeiser
Last active December 27, 2015 13:09
Show Gist options
  • Save davidyeiser/7331573 to your computer and use it in GitHub Desktop.
Save davidyeiser/7331573 to your computer and use it in GitHub Desktop.
Sample code of grabbing temperature value and then either leaving as-is or converting to °C.
// Round temperature values to whole integers
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setMaximumFractionDigits:0];
[numberFormatter setRoundingMode: NSNumberFormatterRoundUp];
// Get the current temp from Current Forecast JSON
// Default is °F, convert to °C if User Settings is set to Celcius (0)
if (unitTemp == 1) {
currentTemp = [numberFormatter stringFromNumber:[currently valueForKeyPath:@"temperature"]];
}
else {
CGFloat nCurrentTemp = [[currently valueForKeyPath:@"temperature"] floatValue];
CGFloat valConvertedTemp = (nCurrentTemp - 32) * 0.5556;
NSNumber *dispConvertedTemp = [NSNumber numberWithFloat:valConvertedTemp];
currentTemp = [numberFormatter stringFromNumber:dispConvertedTemp];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment