So, I worked on the Weather application with the following brief data model
class CurrentWeather
{
private var _cityName: String!
private var _date: String!
private var _weatherType: String!
private var _currentTemp: Double!
var cityName: String
{
if _cityName == nil
{
_cityName = ""
}
return _cityName
}
func downloadWeatherDetails(completed: DownloadComplete)
{
self._cityName = name.capitalized.
print(self._cityName)
self._weatherType = main.capitalized
print(self._weatherType)
self._currentTemp = currentTemp - 273.15
print(self._currentTemp)
completed()
}
}
where type DownloadCompleteis an alias of type()->()
Basically ViewController.swift I created an object and called this function (with closing close syntax)
var currentWeather: CurrentWeather!
override func viewDidLoad()
{
super.viewDidLoad()
currentWeather = CurrentWeather()
currentWeather.downloadWeatherDetails {
self.updateMainUI()
}
}
func updateMainUI()
{
dateLabel.text = currentWeather.date
currentTempLabel.text = String(currentWeather.currentTemp)
locationLabel.text = currentWeather.cityName
currentWeatherTypeLabel.text = currentWeather.weatherType
currentWeatherImage.image = UIImage(named: currentWeather.weatherType)
print("Tested: \(currentWeather.currentTemp)")
print("Tested: \(currentWeather.cityName)")
print("Tested: \(currentWeather.weatherType)")
}
So, the expected result:
Logically,
I created an object CurrentWeather
A function is called downloadWeatherDetailsthat must load the various calculated values in private vars.
Call a user function updateMainUIthat displays various values in the user interface of the application
So the output should look like
Birim.
Clear.
29.134
Tested: 29.134
Tested: Birim
Tested: Clear
But the conclusion that I get is
Tested: 0.0
Tested: (indicating "")
Tested: (indicating "")
Birim
Clear
29.134
, downloadWeatherDetails updateMainUI ? ? - ?
-, .
updateMainUI downloadWeatherDetails ,
currentWeather.downloadWeatherDetails {
}
self.updateMainUI()
. , ?
UPDATE:
vars,
var cityName: String
{
if _cityName == nil
{
_cityName = ""
}
return _cityName
}
2:
( , ): https://github.com/danny311296/Weather-App