قالب وردپرس درنا توس
Home / IOS Development / Network method in the Coordinator class or in background fetch? : iOSProgramming

Network method in the Coordinator class or in background fetch? : iOSProgramming



I have a method that I use to retrieve weather in my coordinator class, and I struggle to understand how to move this method to the background search performFetchWithCompletionHandler . Here is what runs on the launch. I download weather and present it like this:

  func start () {
navigationController.delegate = self
la vc = getCurrentWeather ()
navigationController.pushViewController (vc, animated: false)
}}

func getCurrentWeather () -> UIViewController {
la vc = WeatherViewController.instantiate (storyboard: "Main")
vc.coordinator = self
la currentWeatherURL = NetworkLayer.getCharactersOfURL (weatherFormat: "weather", entityName: "SavedLocation", descriptionFirst: "latitude", descriptionSecond: "longitude")
FetchWeather.downloadCurrentWeather (someURL: currentWeatherURL) {(_, error, weatherModelFromNetwork) in
guard la weatherBuilder = weatherModelFromNetwork else {return}
guard la city = weatherBuilder.cityName, la todaysDate = weatherBuilder.convertedDate, la lowTemp = weatherBuilder.convertedLow, la nowTemp = weatherBuilder.convertedCurrent else {return}
guard la forecastIcon = weatherBuilder.eachDayForecastIcon, la forecast = weatherBuilder.eachDayForecast, la forecastBackground = weatherBuilder.eachDayForecastBackground else {return}
vc.cityName = by
vc.dateToday = TodayDate
vc.lowTemp = lowTemp
vc.currentTemp = nowTemp
vc.forecastIcon = forecastIcon
vc.forecast = forecast
vc.forecastBackground = forecastBackground
DispatchQueue.main.async {[weak self] i
vc.setCurrentWeather ()
}
}
return vc
}

I struggle to understand how to move this to the background method performFetchWithCompletionHandler . If I call the getCurrentWeather () method as coordinator? .GetCurrentWeather (), I don't know how to handle performFetchWithCompletionHandler noData and newData.

Is there a better way to structure my code to do this? Should I FetchWeather.downloadCurrentWeather (someURL: currentWeatherURL) {(newData, error, weatherModelFromNetwork) in separately again in performFetchWithCompletionHandler ?


Source link