Closed puuurm closed 6 years ago
map, flatMap을 사용하여 기존 코드 수를 줄인다. 예) 변경 전:
func temperatures(at index: Int) -> [Float] { var temps = [Float]() forecastStores[index].weekly?.forecasts.forEach { temps.append($0.mainWeather.temperature.rounded()) } return temps }
변경 후:
func temperatures(at index: Int) -> [Float] { return forecastStores[index].weekly?.forecasts.map { $0.mainWeather.temperature.rounded() } ?? [] }
map, flatMap을 사용하여 기존 코드 수를 줄인다. 예) 변경 전:
변경 후: