문의 드립니다.

icopy 6월 18일 PM 01:36 11 0
icopy Profile Image Level 4

xcode 15.3 입니다.
클린 / 재실행 해도 저렇게 에러가 나옵니다.

스크린샷 2024-06-18 오후 1.14.51.png

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 요청 실패"
        }
    }

현재 날씨는 잘 받아서 노출되는데
예보 날씨 에서 저 부분에서 에러가 나서 빌드가 안되네요.


댓글 쓰기
답변하기
마크다운이 처음이라면 [마크다운 설명서]를 확인해 보세요.