Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Playing with Swift 3's Units and Measurements to calculate humidex values.
import Foundation
// The air temperature in degrees Celsius.
var airTemperature = Measurement(value: 29.74, unit: UnitTemperature.celsius)
// The dewpoint temperature in degrees Celsius.
var dewpoint = Measurement(value: 19.08, unit: UnitTemperature.celsius)
// Calculate the humidex value.
let humidex = airTemperature.value + 0.5555 * ((6.11 * exp(5417.7530 * ((1/273.16) - (1/dewpoint.converted(to: UnitTemperature.kelvin).value)))) - 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment