Skip to content

Instantly share code, notes, and snippets.

@bpisano
bpisano / WeatherIcon.swift
Created June 18, 2019 08:29
Embedded code in my Weather article on Medium
extension Weather {
enum Icon: String, Codable {
case clearDay = "clear-day"
case clearNight = "clear-night"
case rain = "rain"
case snow = "snow"
case sleet = "sleet"
case wind = "wind"
@bpisano
bpisano / WeatherManager.swift
Created June 18, 2019 08:27
Embedded code in my Weather article on Medium
class WeatherManager {
static let key: String = "" // Enter your darkSky API Key here
static let baseURL: String = "https://api.darksky.net/forecast/\(key)/"
}
@bpisano
bpisano / HourlyWeather.swift
Created June 18, 2019 08:27
Embedded code in my Weather article on Medium
struct HourlyWeather: Codable, Identifiable {
var id: Date {
return time
}
var time: Date
var temperature: Double
var icon: Weather.Icon
@bpisano
bpisano / DailyWeather.swift
Created June 18, 2019 08:26
Embedded code in my Weather article on Medium
struct DailyWeather: Codable, Identifiable {
var id: Date {
return time
}
var time: Date
var maxTemperature: Double
var minTemperature: Double
var icon: Weather.Icon
@bpisano
bpisano / WeatherList.swift
Created June 18, 2019 08:24
Embedded code in my Weather article on Medium
extension Weather {
struct List<T: Codable & Identifiable>: Codable {
var list: [T]
enum CodingKeys: String, CodingKey {
case list = "data"
@bpisano
bpisano / Weather.swift
Created June 18, 2019 08:12
Embedded code in my Weather article on Medium
struct Weather: Codable {
var current: HourlyWeather
var hours: Weather.List<HourlyWeather>
var week: Weather.List<DailyWeather>
enum CodingKeys: String, CodingKey {
case current = "currently"
case hours = "hourly"