Skip to content

Instantly share code, notes, and snippets.

@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"
@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 / 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 / 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 / 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 / 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 / City.swift
Last active July 4, 2019 08:45
Embedded code in my Weather article on Medium
import SwiftUI
import Combine
class City: BindableObject {
var didChange = PassthroughSubject<City, Never>()
let name: String
var weather: Weather? {
didSet {
@bpisano
bpisano / CityStore.swift
Created June 18, 2019 09:01
Embedded code in my Weather article on Medium
import SwiftUI
import Combine
class CityStore: BindableObject {
let didChange = PassthroughSubject<CityStore, Never>()
var cities: [City] = [City(name: "Chambery")] {
didSet {
didChange.send(self)
@bpisano
bpisano / CityListView.swift
Created June 18, 2019 09:22
Embedded code in my Weather article on Medium
import SwiftUI
struct CityListView : View {
@EnvironmentObject var cityStore: CityStore
@State var isAddingCity: Bool = false
@State private var isEditing: Bool = false
var body: some View {
@bpisano
bpisano / SceneDelegate.swift
Created June 18, 2019 09:37
Embedded code in my Weather article on Medium
import UIKit
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use a UIHostingController as window root view controller
let window = UIWindow(frame: UIScreen.main.bounds)