Created
September 13, 2022 12:18
-
-
Save betty-godier/568b26c2bd0d130947e99c541c8d7185 to your computer and use it in GitHub Desktop.
Create the storage for the measurement data
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 CoreLocation | |
import SwiftUI | |
import WeatherKit | |
struct ContentView: View { | |
@State private var currentSymbol: String? | |
@State private var conditions: String? | |
@State private var currentTemperature: Measurement<UnitTemperature>? | |
@State private var todayHighTemperature: Measurement<UnitTemperature>? | |
@State private var todayLowTemperature: Measurement<UnitTemperature>? | |
var body: some View { | |
ScrollView { | |
VStack { | |
if let currentSymbol { | |
Image(systemName: currentSymbol) | |
.font(.system(size: 200, weight: .light)) | |
} | |
if let conditions { | |
Text(conditions) | |
.font(.title) | |
} | |
} | |
.frame(maxWidth: .infinity) | |
.padding() | |
.background(.black.opacity(0.2)) | |
.clipShape(RoundedRectangle(cornerRadius: 20)) | |
.padding(.horizontal) | |
} | |
.background(.linearGradient(colors: [.blue, Color(hue: 0.6, saturation: 0.8, brightness: 0.5)], startPoint: .top, endPoint: .bottom)) | |
.preferredColorScheme(.dark) | |
.symbolVariant(.fill) | |
.symbolRenderingMode(.multicolor) | |
.task { | |
loadWeather() | |
} | |
} | |
func loadWeather() { | |
Task { | |
let location = CLLocation(latitude: 28.67, longitude: 77.23) | |
let weather = try await WeatherService.shared.weather(for: location) | |
currentSymbol = weather.currentWeather.symbolName | |
conditions = weather.currentWeather.condition.description | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment