Last active
September 13, 2022 11:25
-
-
Save betty-godier/0f7d614d2a9bf7cf8bdf14893689d73d to your computer and use it in GitHub Desktop.
Get our initial load weather call
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? | |
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) | |
} | |
.task { | |
loadWeather() | |
} | |
} | |
func loadWeather() { | |
Task { | |
let location = CLLocation(latitude: 36.3932, longitude: 25.4615) | |
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