0

残念ながら、完了ハンドラーがすべて台無しになっている可能性があります。私がやろうとしているのは、緯度と経度を使用して TimeZone を取得することです。関数全体が TimeZone 型の値を返すようにします。次のコードは、正しい timeZone を取得できるように機能しますが、それがバラバラになるのは戻ってきた段階です。

func getTimeZone(location: CLLocationCoordinate2D, completion: () -> TimeZone) -> TimeZone {
    
    var timeZone = TimeZone(identifier: "timeZone")
    var placemark: CLPlacemark?
    let cllLocation = CLLocation(latitude: location.latitude, longitude: location.longitude)
    let geocoder = CLGeocoder()
    
    geocoder.reverseGeocodeLocation(cllLocation) { placemarks, error in
        
        if let error = error {
            print(error.localizedDescription)
        } else {
            
            if let placemarks = placemarks {
                placemark = placemarks.first
            }
        }
        DispatchQueue.main.async {
            
            if let optTime = placemark?.timeZone {
                timeZone = optTime
            }

            return completion()
        }
    }
}
4

3 に答える 3