У меня проблема с отображением названия города. В файле с именем ExploreView я получил следующую ошибку: Тип аргумента '()' не соответствует ожидаемому типу 'View'
Буду благодарен за помощь.
LocationManager.swift
class LocationManager: NSObject, ObservableObject {
private let locationManager = CLLocationManager()
@Published var location : CLLocation? = nil
override init(){
super.init()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.distanceFilter = kCLDistanceFilterNone
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}
}
расширение LocationManager: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.last else{
return
}
self.location = location
}
func convertLatLongToAddress(latitude:Double,longitude:Double){
let geoCoder = CLGeocoder()
let location = CLLocation(latitude: latitude, longitude: longitude)
geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
// Place details
var placeMark: CLPlacemark!
placeMark = placemarks?[0]
// City
if let city = placeMark.subAdministrativeArea {
print(city)
}
})
}
}
ExploreView.swift
struct ExploreView: просмотр {
@ObservedObject private var locationManager = LocationManager()
var body: some View {
let coordinate = self.locationManager.location != nil ?
self.locationManager.location!.coordinate : CLLocationCoordinate2D()
return ZStack{
MapView()
LocationManager().convertLatLongToAddress(latitude: coordinate.latitude, longitude: coordinate.longitude)
}
}
}