قالب وردپرس درنا توس
Home / IOS Development / Downloading data in coordinator pattern, how is VC updated after it is completed? : iOSProgramming

Downloading data in coordinator pattern, how is VC updated after it is completed? : iOSProgramming



I had a method to download the weather in my VC's viewWillAppear originally. It downloaded the data to a structure in the completion merchant and then updated each parameter to VCs whose. I have refactored my code to use a coordinate pattern and I want to move this network to this coordinator.

How do I check if the weather has downloaded and just update VC if all of this is now in the coordinator?

Currently, this coordinator's start () method is running in the app's didFinishLaunchingWithOptions:

  func start () {
navigationController.delegate = self
la launchBefore = UserDefaults.standard.bool (forKey: "hasLaunched")
if started before {
la vc = FrostViewController.instantiate (storyboard: "Main")
vc.coordinator = self

leave currentWeatherURL = self.networkManager.getCharactersOfURL (weatherFormat: "weather")
RetrieveWeather.downloadCurrentWeather (someURL: currentWeatherURL) {weatherModelFromNetwork in
print ("RetrieveWeather.downloadCurrentWeather called in AppCoord start ()")

guard la weatherBuilder = weatherModelFromNetwork else {return}
guard let town = weatherBuilder.cityName other {return}
vc.cityName = by
print (city, "is the city in AppCoord start ()")
guard la todaysDate = weatherBuilder.dateToday other {return}
vc.dateToday = TodayDate
vakt la lowTemp = weatherBuilder.todayLowTemperature else {return}
vc.lowTemp = lowTemp
guard let nowTemp = weatherBuilder.currentTemperature else {return}
vc.currentTemp = nowTemp
guard la speedOfWind = weatherBuilder.windSpeed ​​else {return}
vc.windSpeed ​​= speedOfWind
guard let youOfWind = weatherBuilder.windDegrees else {return}
vc.windDegrees = degOfWind
guard let coverageOfClouds = weatherBuilder.cloudCoverage other {return}
vc.cloudCoverage = coverageOfClouds
}
navigationController.pushViewController (vc, animated: false)
} other {
la vc = PermissionsViewController.instantiate (storyboard: "Permissions")
vc.coordinator = self
navigationController.pushViewController (vc, animated: false)
UserDefaults.standard.set (true, forKey: "hasLaunched")
}
}

With this in the coordinator, the VC view loads before RetrieveWeather.downloadCurrentWeather finishes getting all the data and then loads with nothing. How do I handle something like this with a coordinator pattern?


Source link