You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
privatevarapiKey:String{guardlet filePath =Bundle.main.path(forResource:"APIKey", ofType:"plist")else{fatalError("'APIKey.plist' 파일을 찾을 수 없습니다.")}letplist=NSDictionary(contentsOfFile: filePath)guardlet value = plist?.object(forKey:"OPENWEATHERMAP_KEY")as?Stringelse{fatalError("'APIKey.plist'파일의 'OPHENWEATHERMAP_KEY' 키를 찾을 수 없습니다.")}return value
}publicfunc getWeather(_ lat:Double, _ lon:Double, completion:@escaping(Result<WeatherResponse,NetworkError>)->Void){guardlet url =URL(string:"https://api.openweathermap.org/data/2.5/forecast?lat=\(lat)&lon=\(lon)&appid=\(apiKey)")else{returncompletion(.failure(.badURL))}DispatchQueue.main.async{URLSession.shared.dataTask(with: url){ data, response, error inguardlet data = data, error ==nilelse{returncompletion(.failure(.noData))}letdecoder=JSONDecoder()letweatherResponse=try? decoder.decode(WeatherResponse.self, from: data)iflet weatherResponse = weatherResponse {completion(.success(weatherResponse))}else{completion(.failure(.decodingError))}}.resume()}}