Skip to content

Instantly share code, notes, and snippets.

View barefeettom's full-sized avatar

Tom Brodhurst-Hill barefeettom

View GitHub Profile
import SwiftUI
struct WeatherScene {
@StateObject var viewModel = ViewModel()
}
extension WeatherScene: View {
var body: some View {
List {
TextField("City", text: $viewModel.city)
extension WeatherScene {
class ViewModel: ObservableObject {
@Published var city: String = ""
@Published var countryCode: String = ""
@Published var system: System = .metric
@Published var site: Site?
private var subscribers = Set<AnyCancellable>()
}
}
@barefeettom
barefeettom / Weather+publisher.swift
Last active April 15, 2021 02:59
extension Weather publisher. For article: https://medium.com/p/4ddf8710d1a0/
import Combine
extension Weather {
static func publisher(
city: String,
countryCode: String?,
system: System
) {
publisher(
keyValues: [
@barefeettom
barefeettom / Weather_publisher_multi_line.swift
Last active April 15, 2021 03:00
Weather.publisher() multi line. For article: https://medium.com/p/4ddf8710d1a0/
Weather.publisher(
keyValues: [
.appID: "1234567890abcdef",
.site: "Sydney,AU",
.system: .metric
]
)
@barefeettom
barefeettom / Weather_publisher_one_line.swift
Last active April 15, 2021 03:01
Weather.publisher() one line. For article: https://medium.com/p/4ddf8710d1a0/
Weather.publisher(keyValues: [.appID: "1234567890abcdef", .site: "Sydney,AU", .system: .metric])
@barefeettom
barefeettom / Weather.swift
Last active May 21, 2021 00:42
Fetchable Weather, for article: https://medium.com/p/4ddf8710d1a0/
import BFWFetch
struct Weather: Fetchable {
static let baseURL = URL(string: "https://api.openweathermap.org/data/2.5")!
enum Key: String, FetchKey {
case appID
case site = "q"
case system = "units"
@barefeettom
barefeettom / sydney_site.json
Created April 7, 2021 03:46
Simplified sample JSON response from Open Weather, for article: https://medium.com/p/4ddf8710d1a0/
{
"id": 2147714,
"name": "Sydney",
"weather": [
{
"main": "Clouds",
"description": "few clouds"
}
],
"main": {
@barefeettom
barefeettom / NibReplaceable.swift
Created March 9, 2019 12:16
Simplified summary of NibReplaceable taken from https://github.com/BareFeetWare/BFWControls
class NibView: UIView, NibReplaceable {
open override func awakeAfter(using coder: NSCoder) -> Any? {
guard subviews.isEmpty,
let nibView = replacedByNibView()
else { return self }
return nibView
}
}
@barefeettom
barefeettom / CustomView.swift
Created February 3, 2019 06:31
CustomView subclass of NibView with IBOutlets
import UIKit
import BFWControls
@IBDesignable class CustomView: NibView {
@IBOutlet weak var textLabel: UILabel!
@IBOutlet weak var slider: UISlider!
}
@barefeettom
barefeettom / CustomView.swift
Created February 3, 2019 06:05
CustomView subclass of NibView
import UIKit
import BFWControls
class CustomView: NibView {
}