This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct WeatherScene { | |
@StateObject var viewModel = ViewModel() | |
} | |
extension WeatherScene: View { | |
var body: some View { | |
List { | |
TextField("City", text: $viewModel.city) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
extension Weather { | |
static func publisher( | |
city: String, | |
countryCode: String?, | |
system: System | |
) { | |
publisher( | |
keyValues: [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Weather.publisher( | |
keyValues: [ | |
.appID: "1234567890abcdef", | |
.site: "Sydney,AU", | |
.system: .metric | |
] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Weather.publisher(keyValues: [.appID: "1234567890abcdef", .site: "Sydney,AU", .system: .metric]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": 2147714, | |
"name": "Sydney", | |
"weather": [ | |
{ | |
"main": "Clouds", | |
"description": "few clouds" | |
} | |
], | |
"main": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NibView: UIView, NibReplaceable { | |
open override func awakeAfter(using coder: NSCoder) -> Any? { | |
guard subviews.isEmpty, | |
let nibView = replacedByNibView() | |
else { return self } | |
return nibView | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import BFWControls | |
@IBDesignable class CustomView: NibView { | |
@IBOutlet weak var textLabel: UILabel! | |
@IBOutlet weak var slider: UISlider! | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import BFWControls | |
class CustomView: NibView { | |
} |