Skip to content

Instantly share code, notes, and snippets.

@soxjke
Last active October 26, 2017 15:43
Show Gist options
  • Select an option

  • Save soxjke/01327f4d078d26d4108f9346e597d6d6 to your computer and use it in GitHub Desktop.

Select an option

Save soxjke/01327f4d078d26d4108f9346e597d6d6 to your computer and use it in GitHub Desktop.
enum WeatherValue<Value> {
case single(value: Value)
case minmax(min: Value, max: Value)
}
struct WeatherFeature<T> {
let unit: String
let value: WeatherValue<T>
}
struct DayNightWeather {
let windSpeed: WeatherFeature<Double>
let windDirection: String
let precipitationProbability: Int
let phrase: String
let icon: Int
}
// Since Swift 3.1 there's a neat feature called "Type nesting with generics" is
// around, however implementation is buggy and leads to runtime error
// https://bugs.swift.org/browse/SR-4383
// As a workaround, WeatherValue, WeatherFeature, DayNightWeather are standalone types
struct Weather {
let effectiveDate: Date
let temperature: WeatherFeature<Double>
let realFeel: WeatherFeature<Double>
let day: DayNightWeather
let night: DayNightWeather
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment