xcode 15.3 입니다.
클린 / 재실행 해도 저렇게 에러가 나옵니다.
ForecastView.swift
struct ForecastView: View {
@EnvironmentObject var service: WeatherService
var body: some View {
ForEach(service.forecastList ?? []) { forecast in
HStack {
VStack(alignment: .leading) {
Text(forecast.data)
Text(forecast.time)
}
.font(.caption)
Spacer()
Image(systemName: forecast.icon)
.font(.title3)
Text(forecast.weather)
.font(.title3)
Spacer()
Text(forecast.temperature)
.font(.system(size: 40))
.fontWeight(.ultraLight)
.frame(minWidth: 70, alignment: .trailing)
} // :HSTACK
.foregroundColor(.white)
.padding(.horizontal)
}
}
}
WeatherService.swift
// 현재 날씨와 예보날씨 배열
@Published var currentWeather: CurrentWeather?
@Published var forecastList: [Forecast]?
WeatherService+Api.swift
func fecthWeather(location: CLLocation) async {
do {
let fetchedCurrentWeather: CodableCurrentWeather = try await fetch(type: .weather, location: location)
let fetchedForecast: CodableForecast = try await fetch(type: .forecast, location: location)
DispatchQueue.main.async {
self.currentWeather = CurrentWeather(data: fetchedCurrentWeather)
print(self.currentWeather ?? "no currentWeather")
self.forecastList = fetchedForecast.list.compactMap {
Forecast(data: $0)
}
print(self.forecastList ?? "no forecast")
}
} catch {
lastError = "Api 요청 실패"
}
}
현재 날씨는 잘 받아서 노출되는데
예보 날씨 에서 저 부분에서 에러가 나서 빌드가 안되네요.