LocationManager


var geocoder = CLGeocoder()
var **afterUpdateLocationUpdateWeatherDataWith**: ((String?, String?, Double?, Double?) -> Void)?

func locationManager(_ manager: CLLocationManager, didUpdateLocations **locations**: [CLLocation]) {
    guard let location = **locations**.first else { return }

    // 최근 위치를 기반으로 도시명, 위도 경도 값을 구한다
    geocoder.reverseGeocodeLocation(location) { [weak self] placemarks, error in
        if let error = error {
            print("❌ Error while updating location with \\(error.localizedDescription)")
            return
        }

        if let firstLocation = placemarks?[0] {
            let cityName = firstLocation.locality ?? "-"
            let countryName = firstLocation.country ?? "-"
            let lon = firstLocation.location?.coordinate.longitude ?? 0
            let lat = firstLocation.location?.coordinate.latitude ?? 0

            self?.longitude = lon
            self?.latitude = lat

            self?.locationManager.stopUpdatingLocation()
						// 🙋🏻‍♂️ 클로져로 데이터 전달
						self?.**afterUpdateLocationUpdateWeatherDataWith**?(cityName, countryName, lon, lat)
        }
    }
}

❖ var afterUpdateLocationUpdateWeatherDataWith: ((String?, String?, Double?, Double?) -> Void)?

🙋🏻‍♂️ 옵셔널 클로져