I am working on updating on iOS using Swift.
I have an array with city names, cityNames = ["Chicago", "New York City"]
I implemented an update to update temperature data from the Internet. Therefore, every time I run pull-to-refresh, it goes to the Internet and gets the temperature for each city in the cityNames array.
Here is the update code for
var weatherDetail = [Weather]() // Pull to refresh func refreshData() { var cityNames = [String]() for (index, _) in weatherDetail.enumerate() { let info = weatherDetail[index] cityNames.append(info.cityName) } print(cityNames) weatherDetail.removeAll() for city in cityNames { self.forwardGeocoding(city) } weatherCityTable.reloadData() refreshControl.endRefreshing() }
In the above code, weatherDetail is an array of the model (I'm not sure how to express this, but Weather is a model that contains the names of cities, temperature, sunrise time, high / low temperature.
forwardGeocoding is a function that receives geographic coordination for a city and then sends a request for meteorological data for that city.
Renovation work, the problem I am facing, the first 2.3 times when I pull, works without problems. But as I pull more time, the array will suddenly change to cityNames = ["Chicago", "Chicago"]
Thank you for your help, please let me know if you need more information.
UPDATE:
I deleted weatherDetail.removeAll() , try just adding the same data to the array. After the update, he displays "Chicago", "New York City", "Chicago", "Chicago" . If I update it more times, it prints something like "Chicago", "New York City", "Chicago", "Chicago", "Chicago", "Chicago"
arrays ios uitableview swift pull-to-refresh
f_qi
source share