Last active
December 27, 2015 13:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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